ampsy 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/ampsy.gemspec +26 -0
- data/lib/ampsy.rb +4 -0
- data/lib/ampsy/client.rb +105 -0
- data/lib/ampsy/response.rb +24 -0
- data/lib/ampsy/version.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f0a57152186045b74697c98949d3d9a9e1da650
|
4
|
+
data.tar.gz: 0038b142f464ab3ce50d3d373e72f1d38c79b69e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec6d6de049a3db6ce016a9c5a79cdd43f5f11f8e9f58bfed08b928c2364100dd6d4090115a3ab1d4ec13cc5659552a2eae1276f5065c0379d8ee3f039977cc52
|
7
|
+
data.tar.gz: 7fce4931b125feb898d70e1b897c9782176687f0d4bacdbf2d0ba3c790f3e687f82823891880859a67e99376f53f9d2d9b1aab59458c312f2035a6fb7fed32e7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Anton Rogov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Ampsy
|
2
|
+
|
3
|
+
Ampsy API wrapper.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ampsy'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ampsy
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
client = Ampsy::Client.new 'the-access-token'
|
25
|
+
|
26
|
+
data = client.flips flipbook_id
|
27
|
+
puts data.inspect
|
28
|
+
|
29
|
+
result = client.create_flipbook brand_id, kind: 'crowdbook',
|
30
|
+
title: 'Test Crowdbook'#, ...
|
31
|
+
if result.success?
|
32
|
+
puts result.data.inspect
|
33
|
+
else
|
34
|
+
puts result.error_message
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
client.create_card number: '4111 1111 1111 1111',
|
39
|
+
name: 'Test User',
|
40
|
+
expiration_month: 1,
|
41
|
+
expiration_year: 2020,
|
42
|
+
secret_token: 123
|
43
|
+
|
44
|
+
# ...
|
45
|
+
```
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fliptu/ampsy-gem.
|
50
|
+
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
55
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ampsy.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ampsy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ampsy"
|
8
|
+
spec.version = Ampsy::VERSION
|
9
|
+
spec.authors = ["Anton Rogov"]
|
10
|
+
spec.email = ["anton@blackbits.pro"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ampsy API wrapper}
|
13
|
+
spec.description = %q{Ampsy API wrapper}
|
14
|
+
spec.homepage = "http://github.com/fliptu/ampsy-gem"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency "httparty", "~> 0.13"
|
26
|
+
end
|
data/lib/ampsy.rb
ADDED
data/lib/ampsy/client.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
module Ampsy
|
2
|
+
class Client
|
3
|
+
def initialize(access_token = nil, host = 'https://ampsy.com')
|
4
|
+
@access_token = access_token
|
5
|
+
@host = host
|
6
|
+
end
|
7
|
+
|
8
|
+
def overview
|
9
|
+
get 'overview'
|
10
|
+
end
|
11
|
+
|
12
|
+
def flips(flipbook_id, timestamp = nil)
|
13
|
+
raise ArgumentError, 'flipbook_id is required' unless flipbook_id
|
14
|
+
|
15
|
+
params = {}
|
16
|
+
params[:timestamp] = timestamp if timestamp
|
17
|
+
get "flipbooks/#{flipbook_id}/flips", params
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_flipbook(brand_id, attributes)
|
21
|
+
raise ArgumentError, 'brand_id is required' unless brand_id
|
22
|
+
raise ArgumentError, 'attributes are required' unless attributes
|
23
|
+
|
24
|
+
create "brands/#{brand_id}/flipbooks", data: attributes
|
25
|
+
end
|
26
|
+
|
27
|
+
def plans
|
28
|
+
get 'plans'
|
29
|
+
end
|
30
|
+
|
31
|
+
def subscription(brand_id)
|
32
|
+
raise ArgumentError, 'brand_id is required' unless brand_id
|
33
|
+
|
34
|
+
get "brands/#{brand_id}/subscription"
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_card(attributes)
|
38
|
+
raise ArgumentError, 'attributes are required' unless attributes
|
39
|
+
|
40
|
+
post 'cards', card: attributes
|
41
|
+
end
|
42
|
+
|
43
|
+
def subscribe(brand_id, plan_id, card_token, promo_code = nil)
|
44
|
+
raise ArgumentError, 'brand_id is required' unless brand_id
|
45
|
+
raise ArgumentError, 'plan_id is required' unless plan_id
|
46
|
+
raise ArgumentError, 'card_token is required' unless card_token
|
47
|
+
|
48
|
+
params = { plan_id: plan_id,
|
49
|
+
card: card_token }
|
50
|
+
params[:promo] = promo_code if promo_code
|
51
|
+
put "brands/#{brand_id}/subscription", params
|
52
|
+
end
|
53
|
+
|
54
|
+
def connect_account(brand_id, provider, account_id)
|
55
|
+
raise ArgumentError, 'brand_id is required' unless brand_id
|
56
|
+
raise ArgumentError, 'provider is required' unless provider
|
57
|
+
raise ArgumentError, 'account_id is required' unless account_id
|
58
|
+
|
59
|
+
post "brands/#{brand_id}/accounts/#{provider}", account_id: account_id
|
60
|
+
end
|
61
|
+
|
62
|
+
def disconnect_account(brand_id, provider)
|
63
|
+
raise ArgumentError, 'brand_id is required' unless brand_id
|
64
|
+
raise ArgumentError, 'provider is required' unless provider
|
65
|
+
|
66
|
+
delete "brands/#{brand_id}/accounts/#{network}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def current_user
|
70
|
+
get 'user'
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def get(path, params = {})
|
76
|
+
request(:get, path, params).data
|
77
|
+
end
|
78
|
+
|
79
|
+
def post(path, data = nil)
|
80
|
+
request :post, path, data
|
81
|
+
end
|
82
|
+
|
83
|
+
def create(path, data = nil)
|
84
|
+
request :post, path, data, 201
|
85
|
+
end
|
86
|
+
|
87
|
+
def put(path, data = nil)
|
88
|
+
request :put, path, data
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete(path)
|
92
|
+
request :delete, path
|
93
|
+
end
|
94
|
+
|
95
|
+
def request(method, path, params, success_status = 200)
|
96
|
+
params = { access_token: @access_token }.merge params
|
97
|
+
result = HTTParty.send method, url(path), query: params
|
98
|
+
Response.new result, success_status
|
99
|
+
end
|
100
|
+
|
101
|
+
def url(path)
|
102
|
+
"#{@host}/api/v1/#{path}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Ampsy
|
2
|
+
class Response
|
3
|
+
def initialize(response, success_status)
|
4
|
+
@response = response
|
5
|
+
@success_status = success_status
|
6
|
+
end
|
7
|
+
|
8
|
+
def success?
|
9
|
+
@response.code == @success_status
|
10
|
+
end
|
11
|
+
|
12
|
+
def error?
|
13
|
+
!success?
|
14
|
+
end
|
15
|
+
|
16
|
+
def error_message
|
17
|
+
data['error']
|
18
|
+
end
|
19
|
+
|
20
|
+
def data
|
21
|
+
@response.parsed_response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ampsy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Rogov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.13'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.13'
|
55
|
+
description: Ampsy API wrapper
|
56
|
+
email:
|
57
|
+
- anton@blackbits.pro
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- ampsy.gemspec
|
68
|
+
- lib/ampsy.rb
|
69
|
+
- lib/ampsy/client.rb
|
70
|
+
- lib/ampsy/response.rb
|
71
|
+
- lib/ampsy/version.rb
|
72
|
+
homepage: http://github.com/fliptu/ampsy-gem
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ampsy API wrapper
|
96
|
+
test_files: []
|