big-door-fork 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.
- data/.bundle/config +2 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/Gemfile +12 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/big-door-fork.gemspec +101 -0
- data/features/big-door.feature +34 -0
- data/features/step_definitions/big-door_steps.rb +83 -0
- data/features/support/env.rb +5 -0
- data/lib/big-door.rb +153 -0
- data/lib/big-door/base.rb +45 -0
- data/lib/big-door/currency.rb +25 -0
- data/lib/big-door/named_award.rb +25 -0
- data/lib/big-door/named_award_collection.rb +27 -0
- data/lib/big-door/named_level.rb +25 -0
- data/lib/big-door/named_level_collection.rb +27 -0
- data/lib/big-door/named_transaction.rb +25 -0
- data/lib/big-door/named_transaction_group.rb +27 -0
- data/lib/big-door/request.rb +7 -0
- data/lib/big-door/response_codes.rb +266 -0
- data/lib/big-door/user.rb +69 -0
- data/spec/.rspec +1 -0
- data/spec/big-door_spec.rb +127 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/vcr.rb +7 -0
- data/vcr_cassettes/NamedTransaction/NamedTransaction.yml +213 -0
- data/vcr_cassettes/NamedTransaction/specific.yml +6043 -0
- data/vcr_cassettes/award/award_summary.yml +34 -0
- data/vcr_cassettes/currency/currency.yml +52 -0
- data/vcr_cassettes/currency/currency_type.yml +31 -0
- data/vcr_cassettes/currency/specific.yml +2980 -0
- data/vcr_cassettes/good/good_summary.yml +34 -0
- data/vcr_cassettes/level/level_summary.yml +34 -0
- data/vcr_cassettes/named_transaction/named_transactions.yml +107 -0
- data/vcr_cassettes/named_transaction_group/all.yml +145 -0
- data/vcr_cassettes/named_transaction_group/specific.yml +3171 -0
- data/vcr_cassettes/user/add_points.yml +36 -0
- data/vcr_cassettes/user/all.yml +10035 -0
- data/vcr_cassettes/user/create.yml +4259 -0
- data/vcr_cassettes/user/currency_balance.yml +738 -0
- data/vcr_cassettes/user/delete.yml +28 -0
- data/vcr_cassettes/user/new.yml +5660 -0
- data/vcr_cassettes/user/new_currency_balance.yml +470 -0
- data/vcr_cassettes/user/specific.yml +44 -0
- metadata +182 -0
data/.bundle/config
ADDED
data/.document
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Michael Lavrisha
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= big-door
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Michael Lavrisha. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "big-door-fork"
|
8
|
+
gem.version = "0.0.1"
|
9
|
+
gem.summary = %Q{Fork of Big Door Media gem}
|
10
|
+
gem.description = %Q{A fork of big-door (gem to interact with Big Door Media's API) to support awards and levels better.}
|
11
|
+
gem.email = "mlavrisha@trada.com danieljohnmorris@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/danieljohnmorris/big-door"
|
13
|
+
gem.authors = ["Michael Lavrisha", "Daniel Morris"]
|
14
|
+
gem.add_development_dependency "rspec", "~> 2.0.0.beta.19"
|
15
|
+
gem.add_development_dependency "cucumber", "~> 0.8.5"
|
16
|
+
gem.add_runtime_dependency "httparty", "~>0.6.0"
|
17
|
+
gem.add_runtime_dependency "json", "~>1.4.3"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
#require 'spec/rake/spectask'
|
26
|
+
#Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
+
# spec.libs << 'lib' << 'spec'
|
28
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
+
#end
|
30
|
+
#
|
31
|
+
#Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
+
# spec.libs << 'lib' << 'spec'
|
33
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
34
|
+
# spec.rcov = true
|
35
|
+
#end
|
36
|
+
#
|
37
|
+
#task :spec => :check_dependencies
|
38
|
+
|
39
|
+
# begin
|
40
|
+
# require 'cucumber/rake/task'
|
41
|
+
# Cucumber::Rake::Task.new(:features)
|
42
|
+
#
|
43
|
+
# task :features => :check_dependencies
|
44
|
+
# rescue LoadError
|
45
|
+
# task :features do
|
46
|
+
# abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
|
50
|
+
task :default => :spec
|
51
|
+
|
52
|
+
require 'rake/rdoctask'
|
53
|
+
Rake::RDocTask.new do |rdoc|
|
54
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "big-door #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{big-door-fork}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Lavrisha", "Daniel Morris"]
|
12
|
+
s.date = %q{2010-09-22}
|
13
|
+
s.description = %q{A fork of big-door (gem to interact with Big Door Media's API) to support awards and levels better.}
|
14
|
+
s.email = %q{mlavrisha@trada.com danieljohnmorris@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".bundle/config",
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"big-door-fork.gemspec",
|
29
|
+
"features/big-door.feature",
|
30
|
+
"features/step_definitions/big-door_steps.rb",
|
31
|
+
"features/support/env.rb",
|
32
|
+
"lib/big-door.rb",
|
33
|
+
"lib/big-door/base.rb",
|
34
|
+
"lib/big-door/currency.rb",
|
35
|
+
"lib/big-door/named_award.rb",
|
36
|
+
"lib/big-door/named_award_collection.rb",
|
37
|
+
"lib/big-door/named_level.rb",
|
38
|
+
"lib/big-door/named_level_collection.rb",
|
39
|
+
"lib/big-door/named_transaction.rb",
|
40
|
+
"lib/big-door/named_transaction_group.rb",
|
41
|
+
"lib/big-door/request.rb",
|
42
|
+
"lib/big-door/response_codes.rb",
|
43
|
+
"lib/big-door/user.rb",
|
44
|
+
"spec/.rspec",
|
45
|
+
"spec/big-door_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/support/vcr.rb",
|
48
|
+
"vcr_cassettes/NamedTransaction/NamedTransaction.yml",
|
49
|
+
"vcr_cassettes/NamedTransaction/specific.yml",
|
50
|
+
"vcr_cassettes/award/award_summary.yml",
|
51
|
+
"vcr_cassettes/currency/currency.yml",
|
52
|
+
"vcr_cassettes/currency/currency_type.yml",
|
53
|
+
"vcr_cassettes/currency/specific.yml",
|
54
|
+
"vcr_cassettes/good/good_summary.yml",
|
55
|
+
"vcr_cassettes/level/level_summary.yml",
|
56
|
+
"vcr_cassettes/named_transaction/named_transactions.yml",
|
57
|
+
"vcr_cassettes/named_transaction_group/all.yml",
|
58
|
+
"vcr_cassettes/named_transaction_group/specific.yml",
|
59
|
+
"vcr_cassettes/user/add_points.yml",
|
60
|
+
"vcr_cassettes/user/all.yml",
|
61
|
+
"vcr_cassettes/user/create.yml",
|
62
|
+
"vcr_cassettes/user/currency_balance.yml",
|
63
|
+
"vcr_cassettes/user/delete.yml",
|
64
|
+
"vcr_cassettes/user/new.yml",
|
65
|
+
"vcr_cassettes/user/new_currency_balance.yml",
|
66
|
+
"vcr_cassettes/user/specific.yml"
|
67
|
+
]
|
68
|
+
s.homepage = %q{http://github.com/danieljohnmorris/big-door}
|
69
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
70
|
+
s.require_paths = ["lib"]
|
71
|
+
s.rubygems_version = %q{1.3.7}
|
72
|
+
s.summary = %q{Fork of Big Door Media gem}
|
73
|
+
s.test_files = [
|
74
|
+
"spec/big-door_spec.rb",
|
75
|
+
"spec/spec_helper.rb",
|
76
|
+
"spec/support/vcr.rb"
|
77
|
+
]
|
78
|
+
|
79
|
+
if s.respond_to? :specification_version then
|
80
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
81
|
+
s.specification_version = 3
|
82
|
+
|
83
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
84
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
|
85
|
+
s.add_development_dependency(%q<cucumber>, ["~> 0.8.5"])
|
86
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.6.0"])
|
87
|
+
s.add_runtime_dependency(%q<json>, ["~> 1.4.3"])
|
88
|
+
else
|
89
|
+
s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
|
90
|
+
s.add_dependency(%q<cucumber>, ["~> 0.8.5"])
|
91
|
+
s.add_dependency(%q<httparty>, ["~> 0.6.0"])
|
92
|
+
s.add_dependency(%q<json>, ["~> 1.4.3"])
|
93
|
+
end
|
94
|
+
else
|
95
|
+
s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
|
96
|
+
s.add_dependency(%q<cucumber>, ["~> 0.8.5"])
|
97
|
+
s.add_dependency(%q<httparty>, ["~> 0.6.0"])
|
98
|
+
s.add_dependency(%q<json>, ["~> 1.4.3"])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Feature: Provide API access to Big Door media
|
2
|
+
As a developer
|
3
|
+
I want to access Big Door media's API
|
4
|
+
|
5
|
+
Scenario: Sending a request to get award summary
|
6
|
+
Given I have API credentials
|
7
|
+
When I make a request for "award_summary"
|
8
|
+
Then the response should be "[]"
|
9
|
+
|
10
|
+
Scenario: Creating an end user
|
11
|
+
Given I have API credentials
|
12
|
+
When I create a user named "testers"
|
13
|
+
Then I should receive a "BigDoor::User" object
|
14
|
+
|
15
|
+
Scenario: Checking the currency balance for a user
|
16
|
+
Given I have API credentials
|
17
|
+
And I have a user
|
18
|
+
When I check the user's "currency_balances"
|
19
|
+
Then the response should be "[]"
|
20
|
+
|
21
|
+
Scenario: Adding points to a user's account
|
22
|
+
Given I have API credentials
|
23
|
+
And I have a user
|
24
|
+
And I have a "NamedTransactionGroup" named "Not so basic"
|
25
|
+
When I add "30" points to users's account
|
26
|
+
Then their account should have "30" more points
|
27
|
+
|
28
|
+
Scenario: Checking user level(s)
|
29
|
+
|
30
|
+
Scenario: Setting user level
|
31
|
+
|
32
|
+
Scenario: Checking user awards
|
33
|
+
|
34
|
+
Scenario: Setting user awards
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Givens
|
2
|
+
Given /^I have API credentials$/ do
|
3
|
+
@big_door = BigDoor::Base.new(:app_key => '0deee7386916481199b5cbc16e4800b0', :secret_key => '601d2664219e4886a059eeb251baad46')
|
4
|
+
end
|
5
|
+
|
6
|
+
Given /^I have a user$/ do
|
7
|
+
VCR.use_cassette('user/all', :record => :new_episodes) do
|
8
|
+
@user = @big_door.get_end_user.first
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Given /^I have a "([^"]*)" named "([^"]*)"$/ do |action, name|
|
13
|
+
if action == "NamedTransaction"
|
14
|
+
VCR.use_cassette("NamedTransaction/specific", :record => :new_episodes) do
|
15
|
+
@transaction = BigDoor::NamedTransaction.find(:pub_title => name)
|
16
|
+
end
|
17
|
+
elsif action == 'NamedTransactionGroup'
|
18
|
+
VCR.use_cassette("named_transaction_group/specific", :record => :new_episodes) do
|
19
|
+
@grp_trans = BigDoor::NamedTransactionGroup.find(:pub_title__startswith => name)
|
20
|
+
end
|
21
|
+
@grp_trans.should_not eql(nil)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Whens
|
26
|
+
When /^I make a request for "([^\"]*)"$/ do |arg1|
|
27
|
+
VCR.use_cassette('award/award_summary', :record => :new_episodes) do
|
28
|
+
@response = @big_door.get_award_summary
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
When /^I create a user named "([^\"]*)"$/ do |name|
|
33
|
+
VCR.use_cassette('user/new', :record => :new_episodes) do
|
34
|
+
@response = BigDoor::User.find(name)
|
35
|
+
end
|
36
|
+
@response.class.should eql(BigDoor::User)
|
37
|
+
end
|
38
|
+
|
39
|
+
When /^I check the user's "([^\"]*)"$/ do |action|
|
40
|
+
VCR.use_cassette('user/all', :record => :new_episodes) do
|
41
|
+
@response = @user.send action
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
When /^I add "([^\"]*)" points to users's account$/ do |points|
|
46
|
+
VCR.use_cassette('user/currency_balance', :match_requests_on => {:path => /end_user\/#{@user.end_user_login}\/currency_balance/}) do
|
47
|
+
@old_points = @user.get_currency_balance(@currency)
|
48
|
+
end
|
49
|
+
|
50
|
+
VCR.use_cassette('user/add_points', :record => :all, :match_requests_on => {:path => /named_transaction_group\/#{@grp_trans.id}\/execute\/#{@user.end_user_login}/}) do
|
51
|
+
@user.add_points(@grp_trans, points.to_i)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Thens
|
56
|
+
Then /^I should have "([^\"]*)" new user$/ do |num|
|
57
|
+
@response = @big_door.get_end_user
|
58
|
+
end
|
59
|
+
|
60
|
+
Then /^I should receive a "([^\"]*)" object$/ do |received_object|
|
61
|
+
if @response.is_a? Array
|
62
|
+
@response.first.class.should eql(received_object.constantize)
|
63
|
+
else
|
64
|
+
@response.class.should eql(eval(received_object))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Then /^I should receive a "([^\"]*)" response code$/ do |response_code|
|
69
|
+
@response.code.should eql(response_code.to_i)
|
70
|
+
end
|
71
|
+
|
72
|
+
Then /^the response should be "([^"]*)"$/ do |arg1|
|
73
|
+
@response.should eql(eval(arg1))
|
74
|
+
end
|
75
|
+
|
76
|
+
Then /^their account should have "([^\"]*)" more points$/ do |points|
|
77
|
+
new_points = {}
|
78
|
+
VCR.use_cassette('user/new_currency_balance', :match_requests_on => {:path => /end_user\/#{@user.end_user_login}\/currency_balance/}) do
|
79
|
+
new_points = @user.get_currency_balance(@currency)
|
80
|
+
end
|
81
|
+
|
82
|
+
new_points["curr_balance"].to_i.should eql(@old_points['curr_balance'].to_i + points.to_i)
|
83
|
+
end
|
data/lib/big-door.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
require 'cgi'
|
6
|
+
require 'uuidtools'
|
7
|
+
|
8
|
+
module BigDoor
|
9
|
+
BASE_URL = 'http://api.bigdoor.com'.freeze
|
10
|
+
BASE_URI = 'api/publisher'.freeze
|
11
|
+
|
12
|
+
class BigDoorError < StandardError; end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def self.included(base)
|
16
|
+
base.extend ClassMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
def remote_id
|
20
|
+
@id || nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.app_key
|
24
|
+
@app_key
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.secret_key
|
28
|
+
@secret_key
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_out_classes(content)
|
32
|
+
output = []
|
33
|
+
unless content.is_a? Array
|
34
|
+
content = Array[content]
|
35
|
+
end
|
36
|
+
content.each do |result|
|
37
|
+
begin
|
38
|
+
output << case result["resource_name"]
|
39
|
+
when 'end_user'
|
40
|
+
User.new(result)
|
41
|
+
when 'currency'
|
42
|
+
Currency.new(result)
|
43
|
+
when 'named_transaction'
|
44
|
+
NamedTransaction.new(result)
|
45
|
+
when 'named_transaction_group'
|
46
|
+
NamedTransactionGroup.new(result)
|
47
|
+
when 'named_level'
|
48
|
+
NamedLevel.new(result)
|
49
|
+
when 'named_level_collection'
|
50
|
+
NamedLevelCollection.new(result)
|
51
|
+
when 'named_award'
|
52
|
+
NamedAward.new(result)
|
53
|
+
when 'named_award_collection'
|
54
|
+
NamedAwardCollection.new(result)
|
55
|
+
else
|
56
|
+
result
|
57
|
+
end
|
58
|
+
rescue
|
59
|
+
debugger
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
output.length == 1 ? output.first : output
|
64
|
+
end
|
65
|
+
|
66
|
+
def perform_request(*args)
|
67
|
+
request_type, action, args, envelope = args
|
68
|
+
envelope = {} unless envelope
|
69
|
+
|
70
|
+
raise BigDoorError, "Unknown request type" unless ['get', 'post', 'put', 'delete'].include? request_type
|
71
|
+
|
72
|
+
query = args
|
73
|
+
params = {}
|
74
|
+
query = {} if (query.is_a? Array and query.empty?) or query.nil?
|
75
|
+
|
76
|
+
action << '/' + query.delete(:id).to_s if query.has_key? :id
|
77
|
+
|
78
|
+
if request_type == 'delete'
|
79
|
+
query = {:delete_token => SecureRandom.hex}
|
80
|
+
elsif ['post', 'put'].include?(request_type)
|
81
|
+
params[:body] = query
|
82
|
+
params[:body][:time] = "%.2f" % Time.now.to_f
|
83
|
+
params[:body][:token] = SecureRandom.hex
|
84
|
+
query = {}
|
85
|
+
|
86
|
+
envelope.each_pair do |key, value|
|
87
|
+
params[:body][key] = value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
params.keys.sort!
|
91
|
+
|
92
|
+
path = [BASE_URI, ClassMethods.app_key, action].join('/')
|
93
|
+
params[:query] = query
|
94
|
+
params[:query][:time] = params[:body][:time] rescue "%.2f" % Time.now.to_f
|
95
|
+
params[:query][:sig] = calculate_sha2_hash(path, params)
|
96
|
+
params[:query][:format] = 'json'
|
97
|
+
url = [BASE_URL, path].join('/')
|
98
|
+
|
99
|
+
p request_type
|
100
|
+
p url
|
101
|
+
p params
|
102
|
+
|
103
|
+
parse_response(BigDoor::Request.send(request_type, url, params))
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
def parse_response(response)
|
108
|
+
if response.response.class.ancestors.include? Net::HTTPClientError
|
109
|
+
raise BigDoorError, "#{response.response.code} #{response.response.message} - #{response.headers['bdm-reason-phrase'].to_s}"
|
110
|
+
end
|
111
|
+
|
112
|
+
if response.parsed_response.is_a? Numeric
|
113
|
+
response_code = BigDoor::ResponseCodes.find response.parsed_response
|
114
|
+
if response_code[:is_error]
|
115
|
+
raise BigDoorError, "#{response_code[:code]} #{response_code[:response_condition]} - #{response_code[:reason_phrase]}"
|
116
|
+
else
|
117
|
+
return true
|
118
|
+
end
|
119
|
+
elsif response.parsed_response.first.is_a? Array
|
120
|
+
content = response.parsed_response.first
|
121
|
+
else
|
122
|
+
content = ([] << response.parsed_response.first)
|
123
|
+
end
|
124
|
+
parse_out_classes(content)
|
125
|
+
end
|
126
|
+
|
127
|
+
def calculate_sha2_hash(path, query)
|
128
|
+
path = '/' + path
|
129
|
+
Digest::SHA2.new(bitlen = 256).update(path + concat_query(query[:query]) + concat_query(query[:body]) + ClassMethods.secret_key).to_s
|
130
|
+
end
|
131
|
+
|
132
|
+
def concat_query(query)
|
133
|
+
str = ''
|
134
|
+
unless query.nil?
|
135
|
+
query.keys.map(&:to_s).sort.each do |key|
|
136
|
+
str << key.to_s + query[key.to_sym].to_s unless [:sig, :format].include?(key)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
str
|
140
|
+
end
|
141
|
+
|
142
|
+
def to_url_params(hash)
|
143
|
+
elements = []
|
144
|
+
hash.each_pair do |key, val|
|
145
|
+
elements << "#{CGI::escape(key.to_s)}=#{CGI::escape(val.to_s)}"
|
146
|
+
end
|
147
|
+
elements.join('&')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
153
|
+
Dir[File.join(directory, "big-door", "*.rb").to_s].each {|file| require file }
|