Class: Coyodlee::RequestBuilder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/coyodlee/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri_builder) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.


14
15
16
17
# File 'lib/coyodlee/connection.rb', line 14

def initialize(uri_builder)
  @uri_builder = uri_builder
  @session_authorization = SessionAuthorization.create
end

Instance Attribute Details

#session_authorizationObject (readonly)

Returns the value of attribute session_authorization


12
13
14
# File 'lib/coyodlee/connection.rb', line 12

def session_authorization
  @session_authorization
end

Instance Method Details

#authorize_cobrand(cobrand_session_token) ⇒ Object


26
27
28
29
# File 'lib/coyodlee/connection.rb', line 26

def authorize_cobrand(cobrand_session_token)
  token = SessionToken.new cobrand_session_token
  @session_authorization.cobrand_session_token = token
end

#authorize_user(user_session_token) ⇒ Object


21
22
23
24
# File 'lib/coyodlee/connection.rb', line 21

def authorize_user(user_session_token)
  token = SessionToken.new user_session_token
  @session_authorization.user_session_token = token
end

#build(method, resource_path, headers: {}, params: {}, body: nil) ⇒ Object


31
32
33
34
35
36
37
38
# File 'lib/coyodlee/connection.rb', line 31

def build(method, resource_path, headers: {}, params: {}, body: nil)
  q = params.empty? ? nil : build_query(params)
  uri = @uri_builder.build(resource_path, query: q)
  http_constructor(method).new(uri).tap do |req|
    add_headers(req, headers)
    req.body = body if body
  end
end