distimo 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0df1e14a7e1809e481cadbbf4b7eb268c373ad2
4
+ data.tar.gz: 0226224dc68dcf326b06c074a23e7fbab42d2929
5
+ SHA512:
6
+ metadata.gz: 341e0869cf9891441b5e00314d282f289bbc6dee54bd266fe3a84678af726d2d27028bdc5037d3f1e91d4a63f69ea95a72763521740748305bc2c584f752b032
7
+ data.tar.gz: 83fdda0b71a57caa77e691f4f33c69b91cf45b5b77507e37aee05a0eea3b7dfb51d2d7762025b3721729e2a194f57a810af2670225c9971fa90a886969ebe37b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'yard'
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ gem 'pry-rescue'
9
+ gem 'pry-stack_explorer', :platforms => :mri_19
10
+ gem 'pry-debugger', :platforms => :mri_19
11
+ end
12
+
13
+ group :test do
14
+ gem 'rspec', '>= 2.14'
15
+ gem 'simplecov', :require => false
16
+ gem 'timecop', '0.6.1'
17
+ gem 'webmock'
18
+ end
19
+
20
+ # Specify your gem's dependencies in distimo.gemspec
21
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Yuri Barbashov
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,29 @@
1
+ # Distimo
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'distimo'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install distimo
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+ task :default => :spec
data/distimo.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'distimo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.add_dependency 'httparty'
8
+ spec.name = "distimo"
9
+ spec.version = Distimo::VERSION
10
+ spec.authors = ["Yuri Barbashov"]
11
+ spec.email = ["lolcoltd@gmail.com"]
12
+ spec.description = %q{Distimo API wrapper gem}
13
+ spec.summary = %q{Distimo API wrapper gem}
14
+ spec.homepage = "https://github.com/playa/distimo"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,13 @@
1
+ module Distimo
2
+ module API
3
+ METHODS = [:downloads, :revenues, :ads, :rankings, :ratings, :reviews, :events, :leaderboards]
4
+
5
+ METHODS.each do |name|
6
+ define_method name do |query = {}|
7
+ options = prepare(query)
8
+ self.class.get("/#{name}", options)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require "distimo/api"
2
+ require "httparty"
3
+ module Distimo
4
+ class Client
5
+ include HTTParty
6
+ include Distimo::API
7
+ base_uri 'https://analytics.distimo.com/api/v3/'
8
+
9
+ attr_accessor :public_key, :private_key, :username, :password, :token
10
+
11
+ def initialize opts
12
+ opts.each {|k,v| send("#{k}=",v)}
13
+ end
14
+
15
+ private
16
+
17
+ def prepare query
18
+ time = Time.now.utc.to_i
19
+ hash = prepare_hash query,time
20
+ _query = query.merge(apikey: public_key, hash: hash, t: time)
21
+ _auth = prepare_auth
22
+ {query: _query}.merge(_auth)
23
+ end
24
+
25
+ def prepare_hash query,time
26
+ _query = query.map{|k,v| "#{k}=#{v}"}.join("&")
27
+ OpenSSL::HMAC.hexdigest('sha1', private_key, _query + time.to_s)
28
+ end
29
+
30
+ def prepare_auth
31
+ if token
32
+ {headers: {"Authorization" => "Bearer #{token}"}}
33
+ else
34
+ {basic_auth: {:username => username, :password => password}}
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Distimo
2
+ VERSION = "0.0.1"
3
+ end
data/lib/distimo.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "distimo/version"
2
+ require "distimo/client"
3
+ module Distimo
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ describe Distimo::API do
4
+ subject{
5
+ Distimo::Client.new(private_key: "PrK",
6
+ public_key: "PubK",
7
+ token: "T",
8
+ username: "UN",
9
+ password: "P")
10
+ }
11
+ Distimo::API::METHODS.each do |method|
12
+ describe "##{method}" do
13
+ before do
14
+ stub_request(:get,"https://analytics.distimo.com/api/v3/#{method}").
15
+ with(query: hash_including({"a" => "b"}))
16
+ end
17
+ it{ subject.send(method,{a: "b"}) }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,59 @@
1
+ require "helper"
2
+
3
+ describe Distimo::Client do
4
+
5
+ describe "#initialize" do
6
+ subject{
7
+ Distimo::Client.new(private_key: "PrK",
8
+ public_key: "PubK",
9
+ token: "T",
10
+ username: "UN",
11
+ password: "P")
12
+ }
13
+
14
+ its(:private_key){should eq("PrK")}
15
+ its(:public_key){should eq("PubK")}
16
+ its(:token){should eq("T")}
17
+ its(:username){should eq("UN")}
18
+ its(:password){should eq("P")}
19
+ end
20
+
21
+ describe "auth" do
22
+ context "with token" do
23
+ let(:client_with_token){
24
+ Distimo::Client.new(private_key: "PrK",
25
+ public_key: "PubK",
26
+ token: "TOKEN",
27
+ username: "UN",
28
+ password: "P")
29
+ }
30
+ before do
31
+ stub_request(:get,"https://analytics.distimo.com/api/v3/downloads" ).
32
+ with({ headers: {"Authorization" => "Bearer TOKEN"}, query: hash_including({})})
33
+ end
34
+ it "should set auth token" do
35
+ client_with_token.downloads({})
36
+ end
37
+ end
38
+
39
+ context "without token" do
40
+ let(:client_without_token){
41
+ Distimo::Client.new(private_key: "PrK",
42
+ public_key: "PubK",
43
+ username: "user",
44
+ password: "pass")
45
+ }
46
+ before do
47
+ stub_request(:get,"https://user:pass@analytics.distimo.com/api/v3/downloads" ).
48
+ with({ headers: {}, query: hash_including({})})
49
+ end
50
+ it "should set auth token" do
51
+ client_without_token.downloads({})
52
+ end
53
+ end
54
+
55
+
56
+ end
57
+
58
+
59
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
4
+ SimpleCov.start
5
+
6
+ require 'distimo'
7
+ require 'rspec'
8
+ require 'timecop'
9
+ require 'webmock/rspec'
10
+
11
+ WebMock.disable_net_connect!
12
+
13
+ RSpec.configure do |config|
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = :expect
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: distimo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuri Barbashov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-04 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Distimo API wrapper gem
56
+ email:
57
+ - lolcoltd@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - distimo.gemspec
68
+ - lib/distimo.rb
69
+ - lib/distimo/api.rb
70
+ - lib/distimo/client.rb
71
+ - lib/distimo/version.rb
72
+ - spec/distimo/api_spec.rb
73
+ - spec/distimo/client_spec.rb
74
+ - spec/helper.rb
75
+ homepage: https://github.com/playa/distimo
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Distimo API wrapper gem
99
+ test_files:
100
+ - spec/distimo/api_spec.rb
101
+ - spec/distimo/client_spec.rb
102
+ - spec/helper.rb
103
+ has_rdoc: