Skip to content

Commit

Permalink
Merge pull request #4 from thehung111/master
Browse files Browse the repository at this point in the history
Add user agent for HTTP client
  • Loading branch information
yulu authored Nov 27, 2016
2 parents a48f888 + 22fe117 commit 85592c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ViSearchSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|


s.name = "ViSearchSDK"
s.version = "1.0"
s.version = "1.0.1"
s.summary = "A Visual Search API solution (Swift SDK)"

s.description = <<-DESC
Expand Down Expand Up @@ -44,7 +44,7 @@ Pod::Spec.new do |s|
# Not including the public_header_files will make all headers public.
#

s.source_files = "ViSearchSDK", "ViSearchSDK/ViSearchSDK/**/*.{h,m,swift}"
s.source_files = "ViSearchSDK/ViSearchSDK/**/*.{h,swift}"
#s.exclude_files = "Classes/Exclude"

# s.public_header_files = "Classes/**/*.h"
Expand Down
11 changes: 11 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/ViSearchClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ open class ViSearchClient: NSObject, URLSessionDelegate {
public var timeoutInterval : TimeInterval = 10 // how long to timeout request
public var requestSerialization: ViRequestSerialization

public var userAgent : String = "ViSenze-Swift-SDK/1.0.1"
private static let userAgentHeader : String = "X-Requested-With"


// MARK: constructors
public init?(baseUrl: String, accessKey: String , secret: String) {
Expand Down Expand Up @@ -101,6 +104,7 @@ open class ViSearchClient: NSObject, URLSessionDelegate {

let boundary = ViMultipartFormData.randomBoundary()
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

request.httpBody = ViMultipartFormData.encode(imageData: imageData, boundary: boundary);

// make tracking call to record the action
Expand Down Expand Up @@ -157,6 +161,7 @@ open class ViSearchClient: NSObject, URLSessionDelegate {

let deviceUid = UidHelper.uniqueDeviceUid()
request.addValue("uid=\(deviceUid)", forHTTPHeaderField: "Cookie")
request.addValue(getUserAgentValue() , forHTTPHeaderField: ViSearchClient.userAgentHeader )

session.dataTask(with: request as URLRequest, completionHandler:{
(data, response, error) in
Expand Down Expand Up @@ -236,6 +241,8 @@ open class ViSearchClient: NSObject, URLSessionDelegate {
successHandler: @escaping SuccessHandler,
failureHandler: @escaping FailureHandler) -> URLSessionTask
{
request.addValue(getUserAgentValue() , forHTTPHeaderField: ViSearchClient.userAgentHeader )

let task = session.dataTask(with: request as URLRequest , completionHandler:{
(data, response, error) in
if (error != nil) {
Expand All @@ -255,5 +262,9 @@ open class ViSearchClient: NSObject, URLSessionDelegate {
return task
}

private func getUserAgentValue() -> String{
return userAgent ;
}


}
2 changes: 1 addition & 1 deletion ViSearchSDK/ViSearchSDK/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.0.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 85592c1

Please sign in to comment.