Class: Mushikago::Http::Client
- Inherits:
-
Object
- Object
- Mushikago::Http::Client
- Defined in:
- lib/mushikago/http/client.rb
Overview
Mushikagoサービスに接続するクライアント
Direct Known Subclasses
Mushikago::Hotaru::Client, Mitsubachi::Client, Tombo::Client
Instance Attribute Summary (collapse)
-
- (String) api_key
readonly
Api_key.
-
- (Signer) signer
readonly
Signer.
-
- (Boolean) use_ssl
readonly
Use_ssl.
Instance Method Summary (collapse)
-
- (Client) initialize(options = {})
constructor
A new instance of Client.
-
- (Mushikago::Http::Response) send_request(request)
Response.
Constructor Details
- (Client) initialize(options = {})
A new instance of Client
21 22 23 24 25 |
# File 'lib/mushikago/http/client.rb', line 21 def initialize ={} @api_key = ([:api_key] || Mushikago.config.api_key).to_s @signer = Mushikago::Auth::Signer.new(([:secret_key] || Mushikago.config.secret_key).to_s) @use_ssl = .has_key?(:use_ssl) ? [:use_ssl] : Mushikago.config.use_ssl end |
Instance Attribute Details
- (String) api_key (readonly)
Api_key
10 11 12 |
# File 'lib/mushikago/http/client.rb', line 10 def api_key @api_key end |
- (Signer) signer (readonly)
Signer
13 14 15 |
# File 'lib/mushikago/http/client.rb', line 13 def signer @signer end |
- (Boolean) use_ssl (readonly)
Use_ssl
16 17 18 |
# File 'lib/mushikago/http/client.rb', line 16 def use_ssl @use_ssl end |
Instance Method Details
- (Mushikago::Http::Response) send_request(request)
Response
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mushikago/http/client.rb', line 29 def send_request request # add authorization request['api_key'] = api_key request['timestamp'] = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ') request.add_signature!(signer) # send request port = use_ssl ? 443 : 80 port = request.port unless request.port.nil? session = Net::HTTP.new(request.host, port) session.use_ssl = use_ssl session.verify_mode = OpenSSL::SSL::VERIFY_NONE if use_ssl session.start do |http| http_request = request.to_http_request http_response = http.request(http_request) return Mushikago::Http::Response.new(JSON.parse(http_response.body)) end end |