Class: Ampsy::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(access_token = nil, host = 'https://ampsy.com') ⇒ Client

Returns a new instance of Client.



3
4
5
6
# File 'lib/ampsy/client.rb', line 3

def initialize(access_token = nil, host = 'https://ampsy.com')
  @access_token = access_token
  @host = host
end

Instance Method Details

#connect_account(brand_id, provider, account_id) ⇒ Object

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
# File 'lib/ampsy/client.rb', line 54

def (brand_id, provider, )
  raise ArgumentError, 'brand_id is required' unless brand_id
  raise ArgumentError, 'provider is required' unless provider
  raise ArgumentError, 'account_id is required' unless 

  post "brands/#{brand_id}/accounts/#{provider}", account_id: 
end

#create_card(attributes) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
# File 'lib/ampsy/client.rb', line 37

def create_card(attributes)
  raise ArgumentError, 'attributes are required' unless attributes

  post 'cards', card: attributes
end

#create_flipbook(brand_id, attributes) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/ampsy/client.rb', line 20

def create_flipbook(brand_id, attributes)
  raise ArgumentError, 'brand_id is required' unless brand_id
  raise ArgumentError, 'attributes are required' unless attributes

  create "brands/#{brand_id}/flipbooks", data: attributes
end

#current_userObject



69
70
71
# File 'lib/ampsy/client.rb', line 69

def current_user
  get 'user'
end

#disconnect_account(brand_id, provider) ⇒ Object

Raises:

  • (ArgumentError)


62
63
64
65
66
67
# File 'lib/ampsy/client.rb', line 62

def (brand_id, provider)
  raise ArgumentError, 'brand_id is required' unless brand_id
  raise ArgumentError, 'provider is required' unless provider

  delete "brands/#{brand_id}/accounts/#{network}"
end

#flips(flipbook_id, timestamp = nil) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
# File 'lib/ampsy/client.rb', line 12

def flips(flipbook_id, timestamp = nil)
  raise ArgumentError, 'flipbook_id is required' unless flipbook_id

  params = {}
  params[:timestamp] = timestamp if timestamp
  get "flipbooks/#{flipbook_id}/flips", params
end

#overviewObject



8
9
10
# File 'lib/ampsy/client.rb', line 8

def overview
  get 'overview'
end

#plansObject



27
28
29
# File 'lib/ampsy/client.rb', line 27

def plans
  get 'plans'
end

#subscribe(brand_id, plan_id, card_token, promo_code = nil) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
# File 'lib/ampsy/client.rb', line 43

def subscribe(brand_id, plan_id, card_token, promo_code = nil)
  raise ArgumentError, 'brand_id is required' unless brand_id
  raise ArgumentError, 'plan_id is required' unless plan_id
  raise ArgumentError, 'card_token is required' unless card_token

  params = { plan_id: plan_id,
             card: card_token }
  params[:promo] = promo_code if promo_code
  put "brands/#{brand_id}/subscription", params
end

#subscription(brand_id) ⇒ Object

Raises:

  • (ArgumentError)


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

def subscription(brand_id)
  raise ArgumentError, 'brand_id is required' unless brand_id

  get "brands/#{brand_id}/subscription"
end