Class: Gumrider
- Inherits:
-
Object
- Object
- Gumrider
- Defined in:
- lib/gumrider.rb
Defined Under Namespace
Classes: Link
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(email, password) ⇒ Gumrider
constructor
A new instance of Gumrider.
- #link(id = false) ⇒ Object
- #links ⇒ Object
Constructor Details
#initialize(email, password) ⇒ Gumrider
Returns a new instance of Gumrider.
9 10 11 12 13 |
# File 'lib/gumrider.rb', line 9 def initialize(email, password) @email = email @password = password @endpoint = 'https://gumroad.com/api/v1' end |
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
7 8 9 |
# File 'lib/gumrider.rb', line 7 def endpoint @endpoint end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/gumrider.rb', line 7 def token @token end |
Instance Method Details
#authenticate ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gumrider.rb', line 15 def authenticate response = Crack::JSON.parse Http.post @endpoint + '/sessions', :form => { :email => @email, :password => @password } if response["success"] @token = Base64.encode64(response["token"] + ":") true else false end end |
#link(id = false) ⇒ Object
26 27 28 |
# File 'lib/gumrider.rb', line 26 def link(id = false) Gumrider::Link.new id, @token, @endpoint end |
#links ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gumrider.rb', line 30 def links response = Crack::JSON.parse Http.with(:Authorization => 'Basic ' + @token).get @endpoint + '/links' if response["success"] links = [] response["links"].each do |item| link = Gumrider::Link.new(false, @token, @endpoint) link.name = item["name"] link.url = item["url"] link.price = item["price"] / 100 link.description = item["description"] link.id = item["id"] link.currency = item["currency"] links.push link end links else [] end end |