Class: G5IntegrationsUpdatable::FeedFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/g5_integrations_updatable/feed_fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ FeedFetcher

Returns a new instance of FeedFetcher.



3
4
5
# File 'lib/g5_integrations_updatable/feed_fetcher.rb', line 3

def initialize(uri)
  @uri = uri
end

Instance Method Details

#access_tokenObject



22
23
24
# File 'lib/g5_integrations_updatable/feed_fetcher.rb', line 22

def access_token
  @access_token ||= G5AuthenticationClient::Client.new.get_access_token
end

#processObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/g5_integrations_updatable/feed_fetcher.rb', line 7

def process
  response = HTTParty.get(@uri, {query:   {access_token: access_token},
                                 headers: {'Content-Type' => 'application/json',
                                           'Accept' => 'application/json'}})

  case response.code.to_i
    when 200
      JSON.parse(response.body).values.first
    when 404
      raise G5IntegrationsUpdatable::RecordNotFoundException.new("Couldn't find record at URL '#{@uri}'")
    else
      raise G5IntegrationsUpdatable::Error.new("I got an unexpected response code '#{response.code}'")
  end
end