Class: Rocky::Client
- Inherits:
-
Object
- Object
- Rocky::Client
- Includes:
- HTTParty, Registrations, StateRequirements
- Defined in:
- lib/rockthevote/client.rb,
lib/rockthevote/client/registrations.rb,
lib/rockthevote/client/state_requirements.rb
Defined Under Namespace
Modules: Registrations, StateRequirements
Instance Method Summary collapse
-
#initialize(env, api_key = nil, api_version = nil) ⇒ Client
constructor
A new instance of Client.
- #perform_get_request(path, options = {}) ⇒ Object
- #perform_post_request(path, options = {}) ⇒ Object
Methods included from Registrations
Methods included from StateRequirements
Constructor Details
#initialize(env, api_key = nil, api_version = nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rockthevote/client.rb', line 13 def initialize(env, api_key=nil, api_version=nil) @env ||= "staging" @api_key ||= ENV["ROCKY_API_KEY"] @api_version ||= "4" if env == "production" url_prefix = "register.rockthevote.com" elsif env == "staging" url_prefix = "staging.rocky.rockthevote.com" else raise StandardError.new "Please specify either a 'production' or 'staging' env argument." end @base_uri = "https://#{url_prefix}/api/v#{@api_version}" self.class..merge!(headers: { 'Authorization' => "Bearer #{api_key}" }) end |
Instance Method Details
#perform_get_request(path, options = {}) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rockthevote/client.rb', line 31 def perform_get_request(path, = {}) url = "#{@base_uri}#{path}" response = self.class.get(url, { query: }) body = response.parsed_response body.define_singleton_method(:_response) { response } return body end |
#perform_post_request(path, options = {}) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rockthevote/client.rb', line 40 def perform_post_request(path, = {}) url = "#{@base_uri}#{path}" response = self.class.post(url, { body: }) body = response.parsed_response body.define_singleton_method(:_response) { response } return body end |