Class: Mushikago::Http::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mushikago/http/client.rb

Overview

Mushikagoサービスに接続するクライアント

Direct Known Subclasses

Tombo::Client

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Client) initialize(options = {})

A new instance of Client

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :api_key(Configured (String)

    value) APIキー

  • :secret_key(Configured (String)

    value) 秘密鍵



16
# File 'lib/mushikago/http/client.rb', line 16

def initialize options={}

Instance Attribute Details

- (String) api_key (readonly)

Api_key

Returns:

  • (String)

    api_key



8
9
10
# File 'lib/mushikago/http/client.rb', line 8

def api_key
  @api_key
end

- (Signer) signer (readonly)

Signer

Returns:

  • (Signer)

    signer



11
12
13
# File 'lib/mushikago/http/client.rb', line 11

def signer
  @signer
end

Instance Method Details

- (Mushikago::Http::Response) send_request(request)

Response

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mushikago/http/client.rb', line 23

def send_request request
  # add authorization
  request.set_param('api_key', api_key)
  request.set_param('timestamp', Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ'))
  request.add_signature!(signer)

  # send request
  Net::HTTP.start(request.host, request.port) 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