Class: Shortybit::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/shortybit/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.



11
12
13
# File 'lib/shortybit/client.rb', line 11

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/shortybit/client.rb', line 9

def access_token
  @access_token
end

Instance Method Details

#get_clicks(client, bit_link) ⇒ Object

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



18
19
20
21
22
23
24
# 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

Returns hash of link history



27
28
29
30
31
# 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

Returns hash of the saved link



34
35
36
37
38
# 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