Class: Subsify::Client

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



4
5
6
7
8
9
# File 'lib/subsify/client.rb', line 4

def initialize(options={})
  @host = options[:host] || 'subsify.com'
  @protocol = options[:protocol] || 'https'
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
end

Class Method Details

.urlObject



37
38
39
# File 'lib/subsify/client.rb', line 37

def self.url
  "#{@protocol}://#{@client_id}:#{@client_secret}@#{@host}"
end

Instance Method Details

#cancel_subscription(options = {}) ⇒ Object



30
31
32
33
34
35
# File 'lib/subsify/client.rb', line 30

def cancel_subscription(options={})
  res = RestClient.delete(
    "#{self.url}/v1/customers/#{options[:id]}/subscription",
  )
  JSON.parse(res)
end

#create_token(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/subsify/client.rb', line 11

def create_token(options={})
  res = RestClient.post(
    "#{self.url}/v1/tokens",
    {
      :ip_address => options[:ip_address],
      :callback_url => options[:callback],
      :plan => options[:plan]
    }
  )
  return Subsify::Token.new(JSON.parse(res)['token'])
end

#get_customer(options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/subsify/client.rb', line 23

def get_customer(options={})
  res = RestClient.get(
    "#{self.url}/v1/customers/#{options[:id]}",
  )
  return Subsify::Customer.new(JSON.parse(res)['customer'])
end