Class: Gumroad::Link

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, json) ⇒ Link

Returns a new instance of Link.



6
7
8
9
10
11
# File 'lib/gumroad/link.rb', line 6

def initialize(session, json)
  @session = session
  [:id, :name, :url, :description, :price].each do |attribute|
    instance_variable_set(:"@#{attribute}", json[attribute.to_s])
  end
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/gumroad/link.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/gumroad/link.rb', line 4

def id
  @id
end

#jsonObject (readonly)

Returns the value of attribute json.



3
4
5
# File 'lib/gumroad/link.rb', line 3

def json
  @json
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/gumroad/link.rb', line 4

def name
  @name
end

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/gumroad/link.rb', line 4

def price
  @price
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/gumroad/link.rb', line 4

def url
  @url
end

Instance Method Details

#destroyObject



19
20
21
# File 'lib/gumroad/link.rb', line 19

def destroy
  @session.delete("/links/#{id}")
end

#saveObject



13
14
15
16
17
# File 'lib/gumroad/link.rb', line 13

def save
  params = {name: name, url: url, description: description, price: price}
  json = @session.post("/links", params)['link']
  self
end