Class: Gumrider::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, token, endpoint) ⇒ Link

Returns a new instance of Link.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gumrider.rb', line 58

def initialize(id, token, endpoint)
  @token = token
  @endpoint = endpoint

  if id
    response = Crack::JSON.parse Http.with(:Authorization => 'Basic ' + token).get endpoint + '/links/' + id

    if response["success"]
      @name = response["link"]["name"]
      @url = response["link"]["url"]
      @price = response["link"]["price"] / 100
      @description = response["link"]["description"]
      @currency = response["link"]["currency"]
      @short_url = response["link"]["short_url"]

      @id = id
    end
  end
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



56
57
58
# File 'lib/gumrider.rb', line 56

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



56
57
58
# File 'lib/gumrider.rb', line 56

def description
  @description
end

#endpointObject

Returns the value of attribute endpoint.



56
57
58
# File 'lib/gumrider.rb', line 56

def endpoint
  @endpoint
end

#idObject

Returns the value of attribute id.



56
57
58
# File 'lib/gumrider.rb', line 56

def id
  @id
end

#nameObject

Returns the value of attribute name.



56
57
58
# File 'lib/gumrider.rb', line 56

def name
  @name
end

#priceObject

Returns the value of attribute price.



56
57
58
# File 'lib/gumrider.rb', line 56

def price
  @price
end

#short_urlObject

Returns the value of attribute short_url.



56
57
58
# File 'lib/gumrider.rb', line 56

def short_url
  @short_url
end

#tokenObject

Returns the value of attribute token.



56
57
58
# File 'lib/gumrider.rb', line 56

def token
  @token
end

#urlObject

Returns the value of attribute url.



56
57
58
# File 'lib/gumrider.rb', line 56

def url
  @url
end

Instance Method Details

#deleteObject



86
87
88
89
90
# File 'lib/gumrider.rb', line 86

def delete
  response = Crack::JSON.parse Http.with(:Authorization => 'Basic ' + @token).delete @endpoint + '/links/' + @id

  !!response["success"]
end

#saveObject



78
79
80
81
82
83
84
# File 'lib/gumrider.rb', line 78

def save
  if @id
    update
  else
    create
  end
end