Class: Resas::Api::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/resas/api/client.rb

Defined Under Namespace

Classes: Path, Response

Constant Summary collapse

API_ENDPOINT =
'https://opendata.resas-portal.go.jp'

Instance Method Summary collapse

Constructor Details

#initializeClient

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

Returns:

  • (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