Class: ConstantContact::Services::BaseService
- Inherits:
-
Object
- Object
- ConstantContact::Services::BaseService
- Defined in:
- lib/constantcontact/services/base_service.rb
Direct Known Subclasses
AccountService, ActivityService, CampaignScheduleService, CampaignTrackingService, ContactService, ContactTrackingService, EmailMarketingService, EventSpotService, LibraryService, ListService
Class Attribute Summary collapse
-
.access_token ⇒ Object
Returns the value of attribute access_token.
-
.api_key ⇒ Object
Returns the value of attribute api_key.
Class Method Summary collapse
-
.build_url(url, params = nil) ⇒ String
Build a url from the base url and query parameters hash.
-
.get_headers(content_type = 'application/json') ⇒ Hash
Return required headers for making an http request with Constant Contact.
Class Attribute Details
.access_token ⇒ Object
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_key ⇒ Object
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
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
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 |