Class: NOMIS::API::Post
- Inherits:
-
Object
- Object
- NOMIS::API::Post
- Defined in:
- lib/nomis/api/post.rb
Overview
Convenience wrapper around an API call Manages defaulting of params from env vars, and parsing the returned JSON
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(opts = {}) ⇒ Post
constructor
A new instance of Post.
Constructor Details
#initialize(opts = {}) ⇒ Post
Returns a new instance of Post.
16 17 18 19 20 21 |
# File 'lib/nomis/api/post.rb', line 16 def initialize(opts={}) self.auth_token = opts[:auth_token] || default_auth_token(opts) self.base_url = opts[:base_url] || ENV['NOMIS_API_BASE_URL'] self.params = opts[:params] self.path = opts[:path] end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
14 15 16 |
# File 'lib/nomis/api/post.rb', line 14 def auth_token @auth_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
14 15 16 |
# File 'lib/nomis/api/post.rb', line 14 def base_url @base_url end |
#params ⇒ Object
Returns the value of attribute params.
14 15 16 |
# File 'lib/nomis/api/post.rb', line 14 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/nomis/api/post.rb', line 14 def path @path end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nomis/api/post.rb', line 23 def execute uri = URI.join(base_url, path) req = Net::HTTP::Post.new(uri) req['Authorization'] = auth_token req['Accept'] = 'application/json, */*' req['Content-type'] = 'application/json' ParsedResponse.new(post_response(req)) end |