Class: ConstantContact::Services::BaseService

Inherits:
Object
  • Object
show all
Defined in:
lib/constantcontact/services/base_service.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_tokenObject

Returns the value of attribute access_token.



11
12
13
# File 'lib/constantcontact/services/base_service.rb', line 11

def access_token
  @access_token
end

.api_keyObject

Returns the value of attribute api_key.



11
12
13
# File 'lib/constantcontact/services/base_service.rb', line 11

def api_key
  @api_key
end

Class Method Details

.build_url(url, params = nil) ⇒ String

Build a url from the base url and query parameters hash. Query parameters should not be URL encoded because this method will handle that

Parameters:

  • url (String)
    • The base url

  • params (Hash) (defaults to: nil)
    • A hash with query parameters

Returns:

  • (String)
    • the url with query parameters hash



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/constantcontact/services/base_service.rb', line 18

def build_url(url, params = nil)
  if params.respond_to? :each
    params.each do |key, value|
      # Convert dates to CC date format
      if value.respond_to? :iso8601
        params[key] = value.iso8601
      end

      if key.to_s == 'next' && value.match(/^.*?next=(.*)$/)
        params[key] = $1
      end
    end
  else
    params ||= {}
  end

  params['api_key'] = BaseService.api_key
  url += '?' + Util::Helpers.http_build_query(params)
end

.get_headers(content_type = 'application/json') ⇒ Hash

Return required headers for making an http request with Constant Contact

Parameters:

  • content_type (String) (defaults to: 'application/json')
    • The MIME type of the body of the request, default is ‘application/json’

Returns:

  • (Hash)
    • authorization headers



41
42
43
44
45
46
47
48
49
# File 'lib/constantcontact/services/base_service.rb', line 41

def get_headers(content_type = 'application/json')
  {
    :content_type   => content_type,
    :accept         => 'application/json',
    :authorization  => "Bearer #{BaseService.access_token}",
    :user_agent     => "AppConnect Ruby SDK v#{ConstantContact::SDK::VERSION} (#{RUBY_DESCRIPTION})",
    :x_ctct_request_source => "sdk.ruby.#{ConstantContact::SDK::VERSION}"
  }
end