Class: ResasKit::Client
- Inherits:
-
Object
- Object
- ResasKit::Client
- Defined in:
- lib/resas_kit/client.rb
Overview
Client for the RESAS API
Constant Summary collapse
- API_ENDPOINT =
'https://opendata.resas-portal.go.jp'.freeze
- API_VERSION =
'v1'.freeze
- USER_AGENT =
"ResasKit Ruby Gem #{ResasKit::VERSION}".freeze
- METHOD_PREFIX =
'get_'.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
Instance Method Summary collapse
-
#get(path, params = {}) ⇒ ResasKit::Response
Make a HTTP GET request.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new Client object with given options.
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize a new Client object with given options
24 25 26 27 28 29 30 31 |
# File 'lib/resas_kit/client.rb', line 24 def initialize( = {}) @api_key = ENV['RESAS_API_KEY'] @api_version = ENV['RESAS_API_VERSION'] .each do |key, value| instance_variable_set(:"@#{key}", value) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, params = {}) ⇒ Object (private)
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/resas_kit/client.rb', line 73 def method_missing(method, params = {}) if respond_to?(method) path = method.to_s .sub(/\A#{METHOD_PREFIX}/, '') .gsub(/__/, '/') .gsub(/_(.)/) { Regexp.last_match(1).camelize } get(path, params) else super end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/resas_kit/client.rb', line 17 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
17 18 19 |
# File 'lib/resas_kit/client.rb', line 17 def api_version @api_version end |
Instance Method Details
#get(path, params = {}) ⇒ ResasKit::Response
Make a HTTP GET request
38 39 40 |
# File 'lib/resas_kit/client.rb', line 38 def get(path, params = {}) request(:get, path, params) end |