Class: LDA::Client
- Inherits:
-
Object
- Object
- LDA::Client
- Defined in:
- lib/lda_gov/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #all(path, params = {}) ⇒ Object
- #clients ⇒ Object
- #connection ⇒ Object
- #constants ⇒ Object
- #contributions ⇒ Object
-
#filings ⇒ Object
Resource accessors.
- #get(path, params = {}) ⇒ Object
-
#initialize(config = LDA.configuration) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #lobbyists ⇒ Object
- #paginate(path, params = {}) ⇒ Object
- #registrants ⇒ Object
Constructor Details
#initialize(config = LDA.configuration) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/lda_gov/client.rb', line 10 def initialize(config = LDA.configuration) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/lda_gov/client.rb', line 8 def config @config end |
Instance Method Details
#all(path, params = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/lda_gov/client.rb', line 43 def all(path, params = {}) records = [] paginate(path, params) { |response| records.concat(response.results) } records end |
#clients ⇒ Object
63 64 65 |
# File 'lib/lda_gov/client.rb', line 63 def clients @clients ||= Resources::Clients.new(self) end |
#connection ⇒ Object
14 15 16 |
# File 'lib/lda_gov/client.rb', line 14 def connection @connection ||= build_connection end |
#constants ⇒ Object
71 72 73 |
# File 'lib/lda_gov/client.rb', line 71 def constants @constants ||= Resources::Constants.new(self) end |
#contributions ⇒ Object
55 56 57 |
# File 'lib/lda_gov/client.rb', line 55 def contributions @contributions ||= Resources::Contributions.new(self) end |
#filings ⇒ Object
Resource accessors
51 52 53 |
# File 'lib/lda_gov/client.rb', line 51 def filings @filings ||= Resources::Filings.new(self) end |
#get(path, params = {}) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/lda_gov/client.rb', line 18 def get(path, params = {}) response = connection.get(path, compact_params(params)) handle_response(response) rescue Faraday::TimeoutError => e raise ConnectionError, "Request timed out: #{e.}" rescue Faraday::ConnectionFailed => e raise ConnectionError, "Connection failed: #{e.}" end |
#inspect ⇒ Object
75 76 77 |
# File 'lib/lda_gov/client.rb', line 75 def inspect "#<#{self.class} base_url=#{config.base_url.inspect} timeout=#{config.timeout}>" end |
#lobbyists ⇒ Object
67 68 69 |
# File 'lib/lda_gov/client.rb', line 67 def lobbyists @lobbyists ||= Resources::Lobbyists.new(self) end |
#paginate(path, params = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lda_gov/client.rb', line 27 def paginate(path, params = {}) page = 1 iterations = 0 loop do iterations += 1 response = get(path, params.merge(page: page)) yield response break if response.empty? break unless response.next_page? page = response.next_page_number break if page.nil? break if iterations >= config.max_pages end end |
#registrants ⇒ Object
59 60 61 |
# File 'lib/lda_gov/client.rb', line 59 def registrants @registrants ||= Resources::Registrants.new(self) end |