Class: AccessWatch::Client
- Inherits:
-
Object
- Object
- AccessWatch::Client
- Defined in:
- lib/access_watch/client.rb
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
readonly
Returns the value of attribute api_endpoint.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
Instance Method Summary collapse
- #default_headers ⇒ Object
- #get(path, params = nil) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #post(path, data) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
10 11 12 13 14 |
# File 'lib/access_watch/client.rb', line 10 def initialize() @api_secret = [:api_secret] @api_key = [:api_key] or raise "AccessWatch api_key is mandatory." @api_endpoint = [:api_endpoint] || "https://access.watch/api/1.0/" end |
Instance Attribute Details
#api_endpoint ⇒ Object (readonly)
Returns the value of attribute api_endpoint.
8 9 10 |
# File 'lib/access_watch/client.rb', line 8 def api_endpoint @api_endpoint end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/access_watch/client.rb', line 8 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
8 9 10 |
# File 'lib/access_watch/client.rb', line 8 def api_secret @api_secret end |
Instance Method Details
#default_headers ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/access_watch/client.rb', line 31 def default_headers { "Api-Key" => api_key, "Accept" => "application/json", "Content-Type" => "application/json", } end |
#get(path, params = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/access_watch/client.rb', line 23 def get(path, params = nil) uri = URI.parse(api_endpoint + path) uri.query = URI.encode_www_form(params) if params request = Net::HTTP::Get.new(uri.request_uri, default_headers) response = http(uri).request(request) response.body end |
#post(path, data) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/access_watch/client.rb', line 16 def post(path, data) uri = URI(api_endpoint + path) post = Net::HTTP::Post.new(uri.path, default_headers) post.body = data.to_json resp = http(uri).request(post) end |