app_figures 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +11 -0
- data/Gemfile +26 -0
- data/LICENSE.txt +22 -0
- data/README.md +157 -0
- data/Rakefile +19 -0
- data/app_figures.gemspec +23 -0
- data/bin/console +14 -0
- data/lib/app_figures/client.rb +78 -0
- data/lib/app_figures/errors.rb +27 -0
- data/lib/app_figures/version.rb +3 -0
- data/lib/app_figures.rb +11 -0
- data/spec/app_figures/app_figures_spec.rb +37 -0
- data/spec/app_figures/client_spec.rb +41 -0
- data/spec/app_figures/products_spec.rb +54 -0
- data/spec/app_figures/sales_spec.rb +30 -0
- data/spec/spec_helper.rb +69 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 08cffe76a59b4b33cd2a48ab466438cebf100379
|
4
|
+
data.tar.gz: a6caf6be062e96b10fa7181a4ef56e22ccc77328
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d67fe2ef22c50e677ecd44e95618dac2baed4a3c1a5dc9e7b3741a0c565cc179af1a2ee10a55479cd991195eff4801c309acf1b9ca8bd1e3c947a57ea144a326
|
7
|
+
data.tar.gz: c55591f65732d5134438a050d53d9ded06fc0c6e7cbbb07bf5cb74c470edd48b89d4a2887e2e04afdce48c3a558de1aa652fb0514eb9f58e291048e39987770c
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
.DS_Store
|
23
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
group :development, :test do
|
5
|
+
gem 'oj' unless defined?(JRUBY_VERSION)
|
6
|
+
end
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'gem-release', require: false
|
10
|
+
gem 'pry', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test, :rake do
|
14
|
+
gem 'bundler'
|
15
|
+
end
|
16
|
+
|
17
|
+
group :rake do
|
18
|
+
gem 'rake'
|
19
|
+
end
|
20
|
+
|
21
|
+
group :test do
|
22
|
+
gem 'minitest', require: false
|
23
|
+
gem 'minitest-spec-context', require: false
|
24
|
+
gem 'minitest-reporters', require: false
|
25
|
+
gem 'mocha', require: false
|
26
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Shidel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
app_figures
|
2
|
+
===========
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/styleseek/app_figures.svg?branch=master)](https://travis-ci.org/styleseek/app_figures)[![Code Climate](https://codeclimate.com/github/styleseek/app_figures.png)](https://codeclimate.com/github/styleseek/app_figures)
|
5
|
+
|
6
|
+
|
7
|
+
Simple API Client for [AppFigures.com](http://appfigures.com/), supports pulling in products and sales from AppFigures with Basic Auth. Send us a pull request and help us expand the support of API this gem covers
|
8
|
+
|
9
|
+
If this gem doesn't meet your needs, there is an older [appfigures api client](http://rubygems.org/gems/appfigures) that may be better suited, but only supports the AppFigures API `v1`.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'app_figures'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it globally:
|
22
|
+
|
23
|
+
$ gem install app_figures
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Register your app with AppFigures.com
|
28
|
+
|
29
|
+
This gem currently only supports Basic Auth, but still requires you to register your app to get a client key.
|
30
|
+
|
31
|
+
1. While logged into AppFigures, visit: https://appfigures.com/developers/keys
|
32
|
+
2. Click 'Create a New Client', give it a name, and set your permissions. This gem needs at least `READ` access to "Product Meta Data" and "Private Data".
|
33
|
+
3. Click 'Make me an app' to complete the registration and get yoru client key.
|
34
|
+
|
35
|
+
### Configuration
|
36
|
+
|
37
|
+
To configure the gem to access the API, you will need the client key you created above, and the username and password of a user on your AppFigures account.
|
38
|
+
|
39
|
+
The username and password needs to be combined and base64 encoded before being passed to the gem. You can do that easily in the terminal:
|
40
|
+
|
41
|
+
$ echo -n "username:password" | base64
|
42
|
+
|
43
|
+
This is covered in more detail in the [AppFigures API documentation](http://docs.appfigures.com/api/reference/v2/authentication).
|
44
|
+
|
45
|
+
#### ENV variables
|
46
|
+
|
47
|
+
The preferred method of configuring authentication for the gem is through environment variables:
|
48
|
+
|
49
|
+
Two `ENV` vars are needed:
|
50
|
+
|
51
|
+
- `APPFIGURES_CLIENT_KEY` (your client key)
|
52
|
+
- `APPFIGURES_CREDENTIALS` (base 64 encoded username:password)
|
53
|
+
|
54
|
+
Once those are set, you can instantiate a new client:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
AppFigures.client
|
58
|
+
# => #<AppFigures::Client:0x007fc5c304e8f0 @client_key="...", @credentials="...">
|
59
|
+
```
|
60
|
+
#### Options Hash
|
61
|
+
|
62
|
+
You can also pass `AppFigures.client` your authentication values in the options hash:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
AppFigures.client(client_key: 'abc', credentials: 'xyz')
|
66
|
+
# => #<AppFigures::Client:0x007fc5c304e8f0 @client_key="abc", @credentials="xyz">
|
67
|
+
```
|
68
|
+
|
69
|
+
Passed in options will take precedence over the ENV vars.
|
70
|
+
|
71
|
+
|
72
|
+
### Making Requests
|
73
|
+
|
74
|
+
#### Products
|
75
|
+
|
76
|
+
```list_products``` will give all registered products (can be filtered by store) see: http://docs.appfigures.com/products#Listing_all_of_your_products
|
77
|
+
|
78
|
+
```product_by_id``` will give one registered product by it's appfigures id see: http://docs.appfigures.com/products#Getting_a_product_by_its_id
|
79
|
+
|
80
|
+
Examples:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
client = AppFigures.client
|
84
|
+
my_products = client.list_products
|
85
|
+
=> {"397821346"=>
|
86
|
+
{"id"=>397821346,
|
87
|
+
"name"=>"Example app",
|
88
|
+
"developer"=>"Example App maker",
|
89
|
+
"icon"=>
|
90
|
+
"http:/icon.com/icon.png",
|
91
|
+
"vendor_identifier"=>"763309467",
|
92
|
+
"ref_no"=>7634478,
|
93
|
+
"sku"=>"EXAMPLE",
|
94
|
+
"package_name"=>nil,
|
95
|
+
"store_id"=>1,
|
96
|
+
"store"=>"apple",
|
97
|
+
"storefront"=>"apple:ios",
|
98
|
+
"release_date"=>"2013-14-02T05:00:00-05:00",
|
99
|
+
"added_date"=>"2013-14-03T20:17:23-05:00",
|
100
|
+
"updated_date"=>"2014-08-20T02:52:22-04:00",
|
101
|
+
"version"=>"3.0.1",
|
102
|
+
"source"=>
|
103
|
+
{"external_account_id"=>76435,
|
104
|
+
"added_timestamp"=>"2014-06-06T00:00:00",
|
105
|
+
"active"=>true,
|
106
|
+
"hidden"=>false,
|
107
|
+
"type"=>"own"},
|
108
|
+
"type"=>"app",
|
109
|
+
"devices"=>["Handheld", "Tablet"],
|
110
|
+
"children"=>[],
|
111
|
+
"features"=>[],
|
112
|
+
"parent_id"=>nil,
|
113
|
+
"price"=>{"currency"=>"USD", "price"=>"0.00"}},
|
114
|
+
"400718594467"=>
|
115
|
+
{"id"=>40071854567,
|
116
|
+
"name"=>"EXAMPLE app 2",
|
117
|
+
"developer"=>"Example app maker",...}}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
one_product = client.product_by_id("397821346")
|
122
|
+
=> {"id"=>397821346,
|
123
|
+
"name"=>"Example app",
|
124
|
+
"developer"=>"Example app maker",
|
125
|
+
"icon"=>
|
126
|
+
"http:/icon.com/icon.png"
|
127
|
+
"vendor_identifier"=>"763309467",
|
128
|
+
"ref_no"=>7634478,
|
129
|
+
"sku"=>"Example",....}
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
#### Sales
|
134
|
+
|
135
|
+
Example:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
client = AppFigures.client
|
139
|
+
sales = client.sales
|
140
|
+
=> {"downloads"=>4589,
|
141
|
+
"updates"=>11234,
|
142
|
+
"returns"=>0,
|
143
|
+
"net_downloads"=>4589,
|
144
|
+
"promos"=>0,
|
145
|
+
"revenue"=>"0.00",
|
146
|
+
"edu_downloads"=>0,
|
147
|
+
"gifts"=>0,
|
148
|
+
"gift_redemptions"=>0}
|
149
|
+
```
|
150
|
+
|
151
|
+
## Contributing
|
152
|
+
|
153
|
+
1. Fork it ( https://github.com/styleseek/app_figures/fork )
|
154
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
155
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
156
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
157
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
# environment
|
3
|
+
ENV['RACK_ENV'] ||= 'development'
|
4
|
+
|
5
|
+
# load path
|
6
|
+
lib_path = File.expand_path('../lib', __FILE__)
|
7
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
8
|
+
|
9
|
+
# spinning up the FTL drive
|
10
|
+
Bundler.require(:default, :rake, ENV['RACK_ENV'])
|
11
|
+
require 'bundler/gem_tasks'
|
12
|
+
require 'rake/testtask'
|
13
|
+
|
14
|
+
# prepare to jump
|
15
|
+
Rake::TestTask.new do |t|
|
16
|
+
t.libs << "spec"
|
17
|
+
t.pattern = "spec/**/*_spec.rb"
|
18
|
+
end
|
19
|
+
task :default => [:test]
|
data/app_figures.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'app_figures/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "app_figures"
|
8
|
+
spec.version = AppFigures::VERSION
|
9
|
+
spec.authors = ['StyleSeek Engineering']
|
10
|
+
spec.email = ['engineering@styleseek.com']
|
11
|
+
spec.summary = %q{Simple API Client for AppFigures.com}
|
12
|
+
spec.description = %q{Simple API Client for AppFigures.com, supports pulling in products and sales from AppFigures with Basic Auth.}
|
13
|
+
spec.homepage = "https://github.com/styleseek/app_figures"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = nil
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty", "~> 0.13"
|
22
|
+
spec.add_dependency "multi_json", "~> 1.10"
|
23
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['RACK_ENV'] ||= 'development'
|
3
|
+
# load path
|
4
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
5
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
6
|
+
|
7
|
+
# require farm
|
8
|
+
require 'bundler'
|
9
|
+
Bundler.require(:default, ENV['RACK_ENV'])
|
10
|
+
require 'pry'
|
11
|
+
require 'app_figures'
|
12
|
+
|
13
|
+
# fire up the ftl drive
|
14
|
+
Pry.start
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module AppFigures
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'https://api.appfigures.com/v2'
|
7
|
+
|
8
|
+
attr_reader :client_key, :credentials
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
options ||= {}
|
12
|
+
options = default_options.merge(options)
|
13
|
+
|
14
|
+
@client_key = options[:client_key]
|
15
|
+
@credentials = options[:credentials]
|
16
|
+
|
17
|
+
check_configuration!
|
18
|
+
end
|
19
|
+
|
20
|
+
def sales(query = {})
|
21
|
+
response = self.class.get('/sales', query: query, headers: authorization_headers)
|
22
|
+
handle_request_status(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def product_by_id(id)
|
26
|
+
response = self.class.get("/products/#{id}", headers: authorization_headers)
|
27
|
+
handle_request_status(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def list_products(store = nil)
|
31
|
+
if store
|
32
|
+
query = {store: store}
|
33
|
+
else
|
34
|
+
query = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
response = self.class.get("/products/mine", query: query, headers: authorization_headers)
|
38
|
+
handle_request_status(response)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def authorization_headers
|
44
|
+
{
|
45
|
+
'X-Client-Key' => client_key,
|
46
|
+
'Authorization' => "Basic #{credentials}"
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_options
|
51
|
+
{
|
52
|
+
client_key: ENV['APPFIGURES_CLIENT_KEY'],
|
53
|
+
credentials: ENV['APPFIGURES_CREDENTIALS']
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_configuration!
|
58
|
+
if client_key.nil? or client_key == ''
|
59
|
+
raise Errors::AuthorizationError.new('client_key is required.')
|
60
|
+
end
|
61
|
+
|
62
|
+
if credentials.nil? or credentials == ''
|
63
|
+
raise Errors::AuthorizationError.new('credentials is required.')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle_request_status(response)
|
68
|
+
case response.code
|
69
|
+
when 404
|
70
|
+
raise Errors::NotFound.new
|
71
|
+
when 500...600
|
72
|
+
raise Errors::BadRequest.new(response.code)
|
73
|
+
else
|
74
|
+
response
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module AppFigures
|
4
|
+
module Errors
|
5
|
+
class AuthorizationError < StandardError
|
6
|
+
attr_reader :message
|
7
|
+
def initialize(message)
|
8
|
+
@message = message
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class NotFound < StandardError
|
13
|
+
attr_reader :code
|
14
|
+
def initialize
|
15
|
+
@code = 404
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class BadRequest < StandardError
|
20
|
+
attr_reader :code
|
21
|
+
|
22
|
+
def initialize(code)
|
23
|
+
@code = code
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/app_figures.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe AppFigures do
|
6
|
+
context '.client with option hash' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@appfigures = AppFigures.client({client_key: 'your client key', credentials:'base 64 encoded username:password' })
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can configure a client key' do
|
13
|
+
@appfigures.client_key.must_equal 'your client key'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can configure credentials' do
|
17
|
+
@appfigures.credentials.must_equal 'base 64 encoded username:password'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.client with env vars' do
|
23
|
+
before do
|
24
|
+
ENV['APPFIGURES_CLIENT_KEY'] = 'abc'
|
25
|
+
ENV['APPFIGURES_CREDENTIALS'] = '123'
|
26
|
+
end
|
27
|
+
|
28
|
+
after do
|
29
|
+
ENV.delete('APPFIGURES_CLIENT_KEY')
|
30
|
+
ENV.delete('APPFIGURES_CREDENTIALS')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'inits a new client object with ENV vars' do
|
34
|
+
AppFigures.client.must_be_instance_of AppFigures::Client
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe AppFigures::Client do
|
6
|
+
context '.new with env vars' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
ENV['APPFIGURES_CLIENT_KEY'] = 'abc'
|
10
|
+
ENV['APPFIGURES_CREDENTIALS'] = '123'
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
ENV.delete('APPFIGURES_CLIENT_KEY')
|
15
|
+
ENV.delete('APPFIGURES_CREDENTIALS')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'takes an option hash' do
|
19
|
+
client = AppFigures::Client.new({client_key: 'my client key', credentials: "my credentials"})
|
20
|
+
client.client_key.wont_be_nil
|
21
|
+
client.credentials.wont_be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'defualts to env vars if no block or options hash is given' do
|
25
|
+
client = AppFigures::Client.new
|
26
|
+
client.client_key.wont_be_nil
|
27
|
+
client.credentials.wont_be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '.new without env vars' do
|
32
|
+
it 'throws error if credentials or client key is nil' do
|
33
|
+
Proc.new{ AppFigures::Client.new }.must_raise AppFigures::Errors::AuthorizationError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has a base url' do
|
38
|
+
client = AppFigures::Client.new(client_key: 'my client key', credentials: "my credentials")
|
39
|
+
client.class.base_uri.must_equal 'https://api.appfigures.com/v2'
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe AppFigures::Client do
|
6
|
+
context 'products' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@client = AppFigures::Client.new({client_key: 'exampleclientkey', credentials: 'examplebase64encodedstring'})
|
10
|
+
@headers = { 'X-Client-Key' => @client.client_key, 'Authorization' => "Basic #{@client.credentials}" }
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can get a product by id' do
|
14
|
+
@client.class.expects(:get)
|
15
|
+
.with('/products/212135374', headers: @headers)
|
16
|
+
.returns(Response.ok)
|
17
|
+
|
18
|
+
@client.product_by_id(212135374)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'can list all products' do
|
22
|
+
@client.class.expects(:get)
|
23
|
+
.with('/products/mine', query: {}, headers: @headers )
|
24
|
+
.returns(Response.ok)
|
25
|
+
|
26
|
+
@client.list_products
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can list all products scoped to a store' do
|
30
|
+
@client.class.expects(:get)
|
31
|
+
.with('/products/mine', query: {store: 'apple'}, headers: @headers )
|
32
|
+
.returns(Response.ok)
|
33
|
+
|
34
|
+
@client.list_products('apple')
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
it 'throws a not found error for a 404 code' do
|
39
|
+
@client.class.expects(:get)
|
40
|
+
.with('/products/mine', query: {store: 'google_play'}, headers: @headers )
|
41
|
+
.returns(Response.not_found)
|
42
|
+
|
43
|
+
Proc.new{ @client.list_products('google_play') }.must_raise AppFigures::Errors::NotFound
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'throws a bad request error for a 500 to 600 code' do
|
47
|
+
@client.class.expects(:get)
|
48
|
+
.with('/products/mine', query: {store: 'amazon'}, headers: @headers)
|
49
|
+
.returns(Response.bad)
|
50
|
+
|
51
|
+
Proc.new{ @client.list_products('amazon') }.must_raise AppFigures::Errors::BadRequest
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe AppFigures::Client do
|
6
|
+
context '.sales' do
|
7
|
+
before do
|
8
|
+
@client = AppFigures::Client.new(client_key: 'exampleclientkey', credentials: 'examplebase64encodedstring')
|
9
|
+
@headers = { 'X-Client-Key' => @client.client_key, 'Authorization' => "Basic #{@client.credentials}" }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'requests results' do
|
13
|
+
options = { query: {}, headers: @headers }
|
14
|
+
@client.class.expects(:get).with('/sales', options).returns(Response.ok)
|
15
|
+
@client.sales
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'requests results with a start date' do
|
19
|
+
options = { query: { start_date: '2014-01-01' }, headers: @headers }
|
20
|
+
@client.class.expects(:get).with('/sales', options).returns(Response.ok)
|
21
|
+
@client.sales(start_date: '2014-01-01')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises error for bad request' do
|
25
|
+
options = { query: { start_date: '2013-01-01' }, headers: @headers }
|
26
|
+
@client.class.expects(:get).with('/sales', options).returns(Response.bad)
|
27
|
+
Proc.new { @client.sales(start_date: '2013-01-01') }.must_raise AppFigures::Errors::BadRequest
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# bootstrap the environment
|
4
|
+
ENV['RACK_ENV'] = 'test'
|
5
|
+
lib_path = File.expand_path('../lib', __FILE__)
|
6
|
+
($:.unshift lib_path) unless ($:.include? lib_path)
|
7
|
+
|
8
|
+
# require dependencies
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.setup(:default, ENV['RACK_ENV'])
|
11
|
+
|
12
|
+
#require gem
|
13
|
+
require 'app_figures'
|
14
|
+
|
15
|
+
#require BDD Stack
|
16
|
+
require 'mocha/mini_test'
|
17
|
+
require 'minitest/autorun'
|
18
|
+
require "minitest-spec-context"
|
19
|
+
require 'minitest/reporters'
|
20
|
+
|
21
|
+
|
22
|
+
module Response
|
23
|
+
#code from httparty
|
24
|
+
|
25
|
+
def self.last_modified
|
26
|
+
Date.new(2010, 1, 15).to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.content_length
|
30
|
+
'1024'
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.request_object
|
34
|
+
HTTParty::Request.new Net::HTTP::Get, '/'
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.parsed_response
|
38
|
+
lambda { {"foo" => "bar"} }
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.bad
|
42
|
+
response_object = Net::HTTPOK.new('1.1', 500, 'NOT FOUND')
|
43
|
+
response_object.stubs(:body).returns("{foo:'bar'}")
|
44
|
+
response_object['last-modified'] = last_modified
|
45
|
+
response_object['content-length'] = content_length
|
46
|
+
response = HTTParty::Response.new(request_object, response_object, parsed_response)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.not_found
|
50
|
+
response_object = Net::HTTPOK.new('1.1', 404, 'NOT FOUND')
|
51
|
+
response_object.stubs(:body).returns("{foo:'bar'}")
|
52
|
+
response_object['last-modified'] = last_modified
|
53
|
+
response_object['content-length'] = content_length
|
54
|
+
response = HTTParty::Response.new(request_object, response_object, parsed_response)
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.ok
|
59
|
+
response_object = Net::HTTPOK.new('1.1', 200, 'OK')
|
60
|
+
response_object.stubs(:body).returns("{foo:'bar'}")
|
61
|
+
response_object['last-modified'] = last_modified
|
62
|
+
response_object['content-length'] = content_length
|
63
|
+
response = HTTParty::Response.new(request_object, response_object, parsed_response)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
# all systems go
|
69
|
+
MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_figures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- StyleSeek Engineering
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
description: Simple API Client for AppFigures.com, supports pulling in products and
|
42
|
+
sales from AppFigures with Basic Auth.
|
43
|
+
email:
|
44
|
+
- engineering@styleseek.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- app_figures.gemspec
|
56
|
+
- bin/console
|
57
|
+
- lib/app_figures.rb
|
58
|
+
- lib/app_figures/client.rb
|
59
|
+
- lib/app_figures/errors.rb
|
60
|
+
- lib/app_figures/version.rb
|
61
|
+
- spec/app_figures/app_figures_spec.rb
|
62
|
+
- spec/app_figures/client_spec.rb
|
63
|
+
- spec/app_figures/products_spec.rb
|
64
|
+
- spec/app_figures/sales_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/styleseek/app_figures
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.2.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Simple API Client for AppFigures.com
|
90
|
+
test_files:
|
91
|
+
- spec/app_figures/app_figures_spec.rb
|
92
|
+
- spec/app_figures/client_spec.rb
|
93
|
+
- spec/app_figures/products_spec.rb
|
94
|
+
- spec/app_figures/sales_spec.rb
|
95
|
+
- spec/spec_helper.rb
|