Class: G5IntegrationsUpdatable::FeedFetcher
- Inherits:
-
Object
- Object
- G5IntegrationsUpdatable::FeedFetcher
- Defined in:
- lib/g5_integrations_updatable/feed_fetcher.rb
Instance Method Summary collapse
- #access_token ⇒ Object
-
#initialize(uri) ⇒ FeedFetcher
constructor
A new instance of FeedFetcher.
- #process ⇒ Object
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_token ⇒ Object
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 |
#process ⇒ Object
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 |