Class: Resas::Api::Client
- Inherits:
-
Object
- Object
- Resas::Api::Client
- Includes:
- Singleton
- Defined in:
- lib/resas/api/client.rb
Defined Under Namespace
Constant Summary collapse
- API_ENDPOINT =
'https://opendata.resas-portal.go.jp'
Instance Method Summary collapse
- #get(*args) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #path(*args) ⇒ URI::HTTP
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 |
# File 'lib/resas/api/client.rb', line 13 def initialize uri = ::URI.parse( API_ENDPOINT ) @http = Net::HTTP.new( uri.host, uri.port ) @http.use_ssl = ( uri.scheme == 'https' ) @header = { 'X-API-KEY' => ENV[ 'RESAS_API_ACCESS_KEY' ], 'Content-Type' => 'application/json' } # @http.verify_mode = OpenSSL::SSL::VERIFY_NONE end |
Instance Method Details
#get(*args) ⇒ Object
23 24 25 26 27 |
# File 'lib/resas/api/client.rb', line 23 def get( *args ) api_version = Resas::Api.api_version response = @http.get( Resas::Api::Client::Path.get( api_version, *args ), @header ) Resas::Api::Client::Response.new( response ) end |
#path(*args) ⇒ URI::HTTP
30 31 32 33 |
# File 'lib/resas/api/client.rb', line 30 def path( *args ) api_version = Resas::Api.api_version URI.join( API_ENDPOINT, Resas::Api::Client::Path.get( api_version, *args ) ) end |