class Shortybit::Client
Attributes
access_token[RW]
Public Class Methods
new(access_token)
click to toggle source
# File lib/shortybit/client.rb, line 11 def initialize(access_token) @access_token = access_token end
Public Instance Methods
get_clicks(client, bit_link)
click to toggle source
Returns number of clicks for bitlink bit_link is expected to be the shortened url Pass in client to get access token and interpolate in response
# File lib/shortybit/client.rb, line 18 def get_clicks(client, bit_link) response = Faraday.get("#{BASE_URL}#{END_POINT[:clicks]}?access_token=#{client.access_token}&link=#{bit_link}") # Parse JSON parsed_response = JSON.parse(response.body) clicks = parsed_response["data"]["link_clicks"] end
link_history(client)
click to toggle source
Returns hash of link history
# File lib/shortybit/client.rb, line 27 def link_history(client) response = Faraday.get("#{BASE_URL}#{END_POINT[:link_history]}?access_token=#{client.access_token}") parsed_response = JSON.parse(response.body) links = parsed_response["data"]["link_history"] end
link_save(client, long_url)
click to toggle source
Returns hash of the saved link
# File lib/shortybit/client.rb, line 34 def link_save(client, long_url) response = Faraday.get("#{BASE_URL}#{END_POINT[:link_save]}?access_token=#{client.access_token}&longUrl=#{long_url}") parsed_response = JSON.parse(response.body) saved_link = parsed_response["data"]["link_save"] end