cookie_jar 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NmZmODFkYzEwNDgwNTUwNWZkMTc1Zjc5NWQwNmNkNDI2MmVjMTIzNw==
5
+ data.tar.gz: !binary |-
6
+ NWNjNjZiNTZjMjBiY2E3MzIwYzRmOTY2NGE2YWU0OGVkYmE0ZjIzMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmUwYmM1ZGYwMmUyYzkzMDdlYWQ2NzhlZTg5Yjk4ZjFjNDUxNDI5YTBlN2Rl
10
+ MmRhOThhZWI4ZTAwMDRlOTEyOWQ0YTM4ZTQzYzQ0YWY2ODkxYjllYWRkYjgy
11
+ YTQzYTgwMTU5MWY3NDY0NjFjYTVhODI2OTQ4YmU4OTZkOGI2ZWQ=
12
+ data.tar.gz: !binary |-
13
+ NzA0YzVjMzJkYjMxNDliODVkOWQ0NzM2MjY4ODMyMzk1ZDdiNTJhY2M2MDkx
14
+ ZDBmYzhlNDY3MDAzMTRjYzRlNWZmNGM2ZDZlYjQ3OWI0MTA4M2UxNGUxZDZj
15
+ ZGZhZWEzNzViNTEwZjY2MGZmMjE3OGE4ODdkMjU0MTExYjU0YWM=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ biscuit-wallet-wrapper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p448
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cookie_jar.gemspec
4
+ gemspec
5
+
6
+ gem "rspec"
7
+ gem "forgery", "~> 0.5.0"
8
+ gem "debugger"
9
+ gem "ipaddress"
10
+
11
+ group :test do
12
+ gem "webmock"
13
+ gem 'simplecov', :require => false
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aldrin dela Cruz
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
+ # CookieJar::Wallet
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cookie_jar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cookie_jar
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 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,51 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cookie_jar/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "cookie_jar"
8
+ gem.version = CookieJar::Wallet::VERSION
9
+ gem.authors = ["Aldrin dela Cruz & Aljon Aniban"]
10
+ gem.email = ["aldrin@bazinga.com.ph"]
11
+ gem.description = %q{For Rumpus and CookieJar Integration.}
12
+ gem.summary = %q{Rumpus and CookieJar Integration.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "forgery", "~> 0.5.0"
21
+ gem.add_dependency "rest-client"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "debugger"
24
+ gem.add_development_dependency "oauth2"
25
+ gem.add_development_dependency "ipaddress"
26
+ end
27
+
28
+
29
+ ## -*- encoding: utf-8 -*-
30
+ #lib = File.expand_path('../lib', __FILE__)
31
+ #$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
32
+ #require 'bazingerZ/version'
33
+ #
34
+ #Gem::Specification.new do |gem|
35
+ # gem.name = "bazingerZ"
36
+ # gem.version = BazingerZ::VERSION
37
+ # gem.authors = ["Aldrin dela Cruz & Diwa del Mundo & Mark Sargento"]
38
+ # gem.email = ["pair+aldrin+diwadm@bazinga.com.ph"]
39
+ # gem.description = %q{API client for Bazinga World Game Center API.}
40
+ # gem.summary = %q{Bazinga World Game Center API Client}
41
+ # gem.homepage = "https://bitbucket.org/bazingainc/bw-game-center-api-client/"
42
+ #
43
+ # gem.files = `git ls-files`.split($/)
44
+ # gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
45
+ # gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
46
+ # gem.require_paths = ["lib"]
47
+ #
48
+ # gem.add_dependency "forgery", "~> 0.5.0"
49
+ # gem.add_dependency "curb"
50
+ #end
51
+
data/lib/cookie_jar.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'cookie_jar/wallet_base'
2
+ require 'cookie_jar/user'
3
+ require 'cookie_jar/account'
4
+ require 'cookie_jar/banker'
5
+ require 'cookie_jar/transfer'
6
+ require 'cookie_jar/support/errors'
7
+
8
+ module CookieJar
9
+
10
+ end
@@ -0,0 +1,56 @@
1
+ module CookieJar
2
+ module Wallet
3
+ module Account
4
+ def all_accounts
5
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/accounts"
6
+ response = self.get
7
+
8
+ #for successful response, self.get will return array. unless it will return error hash
9
+ if response.is_a?(Hash)
10
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
11
+ raise CookieJar::Error::UserNotFound if response["message"][0..17] == "Couldn't find User"
12
+ end
13
+
14
+ response
15
+ end
16
+
17
+ def get_account(account_id)
18
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/accounts/#{account_id}"
19
+ response = self.get
20
+
21
+ unless response["message"].nil? and response[:code].nil?
22
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
23
+ raise CookieJar::Error::UserNotFound if response["message"][0..17] == "Couldn't find User"
24
+ raise CookieJar::Error::AccountNotFound if response["message"][0..20] == "Couldn't find Account"
25
+ end
26
+
27
+ response
28
+ end
29
+
30
+ def create_account(description)
31
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/accounts"
32
+ response = self.post({:account => { :description => description} })
33
+
34
+ unless response["message"].nil? and response[:code].nil?
35
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
36
+ raise CookieJar::Error::InsufficientParams if response["message"] == "Insufficient parameters."
37
+ end
38
+
39
+ self.account_id = response["id"]
40
+
41
+ end
42
+
43
+ def update_account(account_id, description)
44
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/accounts/#{account_id}"
45
+ response = self.put({:account => { :description => description} })
46
+
47
+ unless response["message"].nil? and response[:code].nil?
48
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
49
+ raise CookieJar::Error::InsufficientParams if response["message"] == "Insufficient parameters."
50
+ end
51
+
52
+ self.account_id = response["id"]
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,75 @@
1
+ require "ipaddress"
2
+
3
+ module CookieJar
4
+ module Wallet
5
+ class Banker < WalletBase
6
+ def initialize(client_id, client_secret, username, password, passcode)
7
+ self.client = OAuth2::Client.new(client_id, client_secret, :site => CookieJar::Wallet::AA_HOST)
8
+ self.token = init_token(username, password, passcode)
9
+ self.user_id = get_user_id
10
+ end
11
+
12
+ def init_token(username, password, passcode)
13
+ self.client.password.get_token(username, password, :passcode => passcode)
14
+ end
15
+
16
+ def all_circulations(user_url, user_ip, user_agent)
17
+ raise CookieJar::Error::InvalidUserIP unless IPAddress.valid? user_ip
18
+
19
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/circulations"
20
+ response = self.get({:user_url => user_url, :user_ip => user_ip, :user_agent => user_agent, :user_id => self.user_id})
21
+
22
+ if response.is_a?(Hash)
23
+ raise CookieJar::Error::InsufficientParams if response["message"] == "Insufficient parameters."
24
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
25
+ end
26
+ response
27
+ end
28
+
29
+ def get_circulation(circulation_id, user_url, user_ip, user_agent)
30
+ raise CookieJar::Error::InvalidUserIP unless IPAddress.valid? user_ip
31
+
32
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1//circulations/#{circulation_id}"
33
+ response = self.get({:user_url => user_url, :user_ip => user_ip, :user_agent => user_agent, :user_id => self.user_id})
34
+ unless response["message"].nil? and response[:code].nil?
35
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
36
+ raise CookieJar::Error::CirculationNotFound if response["message"][0..21] == "Couldn't find Transfer"
37
+ raise CookieJar::Error::InsufficientParams if response["message"] == "Insufficient parameters."
38
+ end
39
+
40
+ response
41
+ end
42
+
43
+ def create_circulation(amount, user_url, user_ip, user_agent)
44
+ raise CookieJar::Error::InvalidUserIP unless IPAddress.valid? user_ip
45
+
46
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/circulations"
47
+ response = self.post({:amount => amount, :user_url => user_url, :user_ip => user_ip, :user_agent => user_agent, :user_id => self.user_id})
48
+
49
+ unless response["message"].nil? and response[:code].nil?
50
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
51
+ raise CookieJar::Error::CreateError if response["message"] == "Creation of circulation failed."
52
+ raise CookieJar::Error::InsufficientParams if response["message"] == "Insufficient parameters."
53
+ end
54
+
55
+ response
56
+ end
57
+
58
+ def activate_circulation(circulation_id, user_url, user_ip, user_agent)
59
+ raise CookieJar::Error::InvalidUserIP unless IPAddress.valid? user_ip
60
+
61
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/circulations/#{circulation_id}/activate"
62
+ response = self.put(:user_url => user_url, :user_ip => user_ip, :user_agent => user_agent, :user_id => self.user_id)
63
+
64
+ unless response["message"].nil? and response[:code].nil?
65
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
66
+ raise CookieJar::Error::InsufficientParams if response["message"] == "Insufficient parameters."
67
+ raise CookieJar::Error::CirculationNotFound if response["message"][0..21] == "Couldn't find Transfer"
68
+ raise CookieJar::Error::CirculationAlreadyActivated if response["message"] == "Circulation is already activated."
69
+ end
70
+
71
+ response
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,81 @@
1
+ module CookieJar
2
+ module Error
3
+ class AccessDenied < StandardError
4
+ def to_s
5
+ "You're not authorized to access the resource"
6
+ end
7
+ end
8
+
9
+ class UserNotFound < StandardError
10
+ def to_s
11
+ "User was not found."
12
+ end
13
+ end
14
+
15
+ class TransferNotFound < StandardError
16
+ def to_s
17
+ "Transfer was not found."
18
+ end
19
+ end
20
+
21
+ class CirculationNotFound < StandardError
22
+ def to_s
23
+ "Circulation was not found."
24
+ end
25
+ end
26
+
27
+ class CirculationAlreadyActivated < StandardError
28
+ def to_s
29
+ "Circulation is already activated."
30
+ end
31
+ end
32
+
33
+ class CreateError < StandardError
34
+ def to_s
35
+ "Creation of circulation failed."
36
+ end
37
+ end
38
+
39
+ class AccountNotFound < StandardError
40
+ def to_s
41
+ "Account was not found."
42
+ end
43
+ end
44
+
45
+ class InsufficientParams < StandardError
46
+ def to_s
47
+ "Insufficient params."
48
+ end
49
+ end
50
+
51
+ class InvalidUserIP < StandardError
52
+ def to_s
53
+ "Invalid USER IP address."
54
+ end
55
+ end
56
+
57
+ class InvalidWithdrawAmount < StandardError
58
+ def to_s
59
+ "Invalid withdraw amount."
60
+ end
61
+ end
62
+
63
+ class TransferPermissionDenied < StandardError
64
+ def to_s
65
+ "You do not have permission to authorize the transfer."
66
+ end
67
+ end
68
+
69
+ class AccountPermissionDenied < StandardError
70
+ def to_s
71
+ "You do not have permission to access the account."
72
+ end
73
+ end
74
+
75
+ class TransferAlreadyInitiated < StandardError
76
+ def to_s
77
+ "Transfer is already initiated."
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,52 @@
1
+ module CookieJar
2
+ module Wallet
3
+ module Transfer
4
+ def create_transfer
5
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/transfers"
6
+ response = self.post
7
+
8
+ unless response["message"].nil? and response[:code].nil?
9
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
10
+ end
11
+
12
+ response
13
+ end
14
+
15
+ def get_transfer(transfer_id)
16
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/transfers/#{transfer_id}"
17
+ response = self.get
18
+
19
+ unless response["message"].nil? and response[:code].nil?
20
+ raise CookieJar::Error::TransferNotFound if response["message"][0..21] == "Couldn't find Transfer"
21
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
22
+ end
23
+
24
+ response
25
+ end
26
+
27
+ def all_transfers
28
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/transfers"
29
+ response = self.get
30
+
31
+ if response.is_a?(Hash)
32
+ raise CookieJar::Error::AccessDenied if response["message"] == "You're not authorized to access the resource" or response[:code] == 401
33
+ end
34
+
35
+ response
36
+ end
37
+
38
+ def activate_transfer(transfer_id, amount, from_account, to_account)
39
+ self.url = "#{CookieJar::Wallet::WALLET_HOST}/v1/users/#{self.user_id}/transfers/#{transfer_id}/transfer"
40
+ response = self.put({:amount => amount, :accounts => { :from_account => from_account, :to_account => to_account }})
41
+
42
+ unless response["message"].nil? and response[:code].nil?
43
+ raise CookieJar::Error::TransferAlreadyInitiated if response["message"] == "Transfer is already initiated."
44
+ raise CookieJar::Error::AccountPermissionDenied if response["message"] == "You do not have permission to access the account."
45
+ raise CookieJar::Error::TransferPermissionDenied if response["message"] == "You do not have permission to access the transfer."
46
+ raise CookieJar::Error::InvalidWithdrawAmount if response["message"] == "Invalid withdraw amount."
47
+ end
48
+ response
49
+ end
50
+ end
51
+ end
52
+ end