Class: AmplifySyndication::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/amplify_syndication/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/amplify_syndication/client.rb', line 7

def initialize
  @http_client = HTTPClient.new
  @base_url = AmplifySyndication.configuration.base_url
  @access_token = AmplifySyndication.configuration.access_token
end

Instance Method Details

#get(endpoint, params = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/amplify_syndication/client.rb', line 13

def get(endpoint, params = {})
  url = "#{@base_url}/#{endpoint}".gsub(%r{//}, '/').sub(%r{:/}, '://')
  headers = {
    "Authorization" => "Bearer #{@access_token}",
    "Accept" => "application/json"
  }
  response = @http_client.get(url, params, headers)
  parse_response(response)
end

#get_with_options(endpoint, options = {}) ⇒ Object



23
24
25
26
# File 'lib/amplify_syndication/client.rb', line 23

def get_with_options(endpoint, options = {})
  query_string = options.map { |key, value| "#{key}=#{value}" }.join("&")
  get("#{endpoint}?#{query_string}")
end