Class: AFMotion::ClientDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/afmotion/http_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientDSL

Returns a new instance of ClientDSL.



3
4
5
# File 'lib/afmotion/http_client.rb', line 3

def initialize(client)
  @client = client
end

Instance Method Details

#authorization(options = {}) ⇒ Object



11
12
13
# File 'lib/afmotion/http_client.rb', line 11

def authorization(options = {})
  @client.authorization = options
end

#header(header, value) ⇒ Object



7
8
9
# File 'lib/afmotion/http_client.rb', line 7

def header(header, value)
  @client.setDefaultHeader(header, value: value)
end

#operation(operation) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/afmotion/http_client.rb', line 15

def operation(operation)
  klass = operation
  if operation.is_a?(Symbol) or operation.is_a?(String)
    klass = case operation.to_s
            when "json"
              AFJSONRequestOperation
            when "plist"
              AFPropertyListRequestOperation
            when "xml"
              AFXMLRequestOperation
            when "http"
              AFHTTPRequestOperation
            else
              raise "Not a valid operation: #{operation.inspect}"
            end
  end

  @client.registerHTTPOperationClass(klass)
end

#parameter_encoding(encoding) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/afmotion/http_client.rb', line 35

def parameter_encoding(encoding)
  enc = encoding
  if encoding.is_a?(Symbol) or encoding.is_a?(String)
    enc = case encoding.to_s
          when "json"
            AFJSONParameterEncoding
          when "plist"
            AFPropertyListParameterEncoding
          when "form"
            AFFormURLParameterEncoding
          else
            p "Not a valid parameter encoding: #{encoding.inspect}; using AFFormURLParameterEncoding"
            AFFormURLParameterEncoding
          end
  end
  @client.parameterEncoding = enc
end