class ShotApiGem::Consumer

Attributes

base_url[R]
header[R]
local_base_url[R]

Public Class Methods

new(api_key) click to toggle source
# 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

Public Instance Methods

create(options) click to toggle source
# File lib/shot_api_gem/consumer.rb, line 26
def create(options)
  response = RestClient.post(
               base_url,
               { given_url: options[:url], slug: options[:slug] },
               header
             )
  Link.new(json_response(response.body))
end
delete(id) click to toggle source
# File lib/shot_api_gem/consumer.rb, line 44
def delete(id)
  response = RestClient.delete(base_url << "/#{id}", header)
  response.code
end
fetch(id) click to toggle source
# 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
fetch_all() click to toggle source
# File lib/shot_api_gem/consumer.rb, line 14
def fetch_all
  response = RestClient.get(base_url, header)
  json_response(response.body)[:links].map do |link|
    Link.new(link)
  end
end
update(id, options) click to toggle source
# File lib/shot_api_gem/consumer.rb, line 35
def update(id, options)
  response = RestClient.patch(
      base_url << "/#{id}",
      { given_url: options[:url], slug: options[:slug], active: options[:active] },
      header
    )
  Link.new(json_response(response.body))
end

Private Instance Methods

json_response(body) click to toggle source
# File lib/shot_api_gem/consumer.rb, line 51
def json_response(body)
  JSON.parse(body, symbolize_names: true)
end