Class: Pinter::Subscription
- Inherits:
-
Object
- Object
- Pinter::Subscription
- Includes:
- HTTParty, Base
- Defined in:
- lib/pinter/subscription.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#recurring ⇒ Object
readonly
Returns the value of attribute recurring.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #cancel ⇒ Object
-
#initialize(attributes) ⇒ Subscription
constructor
A new instance of Subscription.
Methods included from Base
#set_instance_variables_from_hash
Constructor Details
#initialize(attributes) ⇒ Subscription
Returns a new instance of Subscription.
12 13 14 15 16 |
# File 'lib/pinter/subscription.rb', line 12 def initialize(attributes) set_instance_variables_from_hash attributes @user = Pinter::User.new attributes["user"] @product = Pinter::Product.new attributes["product"] end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def created_at @created_at end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def first_name @first_name end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def identifier @identifier end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def last_name @last_name end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def product @product end |
#recurring ⇒ Object (readonly)
Returns the value of attribute recurring.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def recurring @recurring end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def secret @secret end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/pinter/subscription.rb', line 10 def user @user end |
Class Method Details
.all ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pinter/subscription.rb', line 18 def self.all collection = [] raw = get "/subscriptions", :query => { :api_key => Pinter.api_key, :api_secret => Pinter.api_secret } raw.to_a raw.each do |attributes| obj = Pinter::Subscription.new attributes collection << obj end return collection end |
.find(secret) ⇒ Object
31 32 33 34 |
# File 'lib/pinter/subscription.rb', line 31 def self.find(secret) sub = get "/subscriptions/#{secret}", :query => { :api_key => Pinter.api_key, :api_secret => Pinter.api_secret } sub.parsed_response.to_subscription end |
.find_by_identifier(identifier) ⇒ Object
36 37 38 39 40 |
# File 'lib/pinter/subscription.rb', line 36 def self.find_by_identifier(identifier) sub = get "/subscriptions/identifier/#{identifier}", :query => { :api_key => Pinter.api_key, :api_secret => Pinter.api_secret } sub.parsed_response.to_subscription end |
Instance Method Details
#cancel ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pinter/subscription.rb', line 42 def cancel response = Subscription.put "/subscriptions/#{secret}/cancel", :body => { :api_key => Pinter.api_key, :api_secret => Pinter.api_secret } parsed_response = Crack::JSON.parse response.parsed_response if response.headers["status"] == 200 attributes = {:success => true, :message => "Cancelled subscription"} else attributes = {:success => false, :message => parsed_response} end Pinter::Result.new attributes end |