Class: IIJ::Sakagura::Core::QueryClient
- Inherits:
-
Object
- Object
- IIJ::Sakagura::Core::QueryClient
- Defined in:
- lib/iij/sakagura/core/query_client.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #agent ⇒ Object
-
#initialize(opts = {}) ⇒ QueryClient
constructor
A new instance of QueryClient.
- #make_request(action, params = {}) ⇒ Object
- #post(action, params = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ QueryClient
11 12 13 14 15 16 17 |
# File 'lib/iij/sakagura/core/query_client.rb', line 11 def initialize(opts = {}) @endpoint = opts[:endpoint] @access_key = opts[:access_key] @secret_key = opts[:secret_key] @api_version = opts[:api_version] @expire_after = opts[:expire_after] end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
19 20 21 |
# File 'lib/iij/sakagura/core/query_client.rb', line 19 def endpoint @endpoint end |
Instance Method Details
#agent ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/iij/sakagura/core/query_client.rb', line 21 def agent @agent ||= Faraday.new(:url => @endpoint) do |builder| builder.request :signature_v2, :access_key => @access_key, :secret_key => @secret_key, :expire_after => @expire_after builder.request :url_encoded builder.response :iij_sakagura_raise_error builder.response :json, :content_type => /\bjson$/ builder.adapter Faraday.default_adapter end end |
#make_request(action, params = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/iij/sakagura/core/query_client.rb', line 31 def make_request(action, params = {}) { "Action" => action, "APIVersion" => @api_version }.merge(IIJ::Sakagura::Core.hash_to_query(params)) end |
#post(action, params = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/iij/sakagura/core/query_client.rb', line 38 def post(action, params = {}) res = agent.post('/json') do |req| req.body = make_request(action, params) end res.body[action + 'Response'] end |