Class: ShotApiGem::Consumer
- Inherits:
-
Object
- Object
- ShotApiGem::Consumer
- Defined in:
- lib/shot_api_gem/consumer.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#local_base_url ⇒ Object
readonly
Returns the value of attribute local_base_url.
Instance Method Summary collapse
- #create(options) ⇒ Object
- #delete(id) ⇒ Object
- #fetch(id) ⇒ Object
- #fetch_all ⇒ Object
-
#initialize(api_key) ⇒ Consumer
constructor
A new instance of Consumer.
- #update(id, options) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Consumer
Returns a new instance of Consumer.
8 9 10 11 12 |
# File 'lib/shot_api_gem/consumer.rb', line 8 def initialize(api_key) @header = { authorization: api_key } @base_url = 'http://turbo-url.herokuapp.com/api/v1/links' @local_base_url = 'http://localhost:3000/api/v1/links' end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
6 7 8 |
# File 'lib/shot_api_gem/consumer.rb', line 6 def base_url @base_url end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
6 7 8 |
# File 'lib/shot_api_gem/consumer.rb', line 6 def header @header end |
#local_base_url ⇒ Object (readonly)
Returns the value of attribute local_base_url.
6 7 8 |
# File 'lib/shot_api_gem/consumer.rb', line 6 def local_base_url @local_base_url end |
Instance Method Details
#create(options) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/shot_api_gem/consumer.rb', line 26 def create() response = RestClient.post( base_url, { given_url: [:url], slug: [:slug] }, header ) Link.new(json_response(response.body)) end |
#delete(id) ⇒ Object
44 45 46 47 |
# File 'lib/shot_api_gem/consumer.rb', line 44 def delete(id) response = RestClient.delete(base_url << "/#{id}", header) response.code end |
#fetch(id) ⇒ Object
21 22 23 24 |
# File 'lib/shot_api_gem/consumer.rb', line 21 def fetch(id) response = RestClient.get(base_url << "/#{id}", header) Link.new(json_response(response.body)) end |