Module: BigDoor::ClassMethods

Included in:
Base, Currency, NamedTransaction, NamedTransactionGroup, User
Defined in:
lib/big-door.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_keyObject



19
20
21
# File 'lib/big-door.rb', line 19

def self.app_key
	@app_key
end

.included(base) ⇒ Object



15
16
17
# File 'lib/big-door.rb', line 15

def self.included(base)
	base.extend ClassMethods
end

.secret_keyObject



23
24
25
# File 'lib/big-door.rb', line 23

def self.secret_key
	@secret_key
end

Instance Method Details

#parse_out_classes(content) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/big-door.rb', line 27

def parse_out_classes(content)
	output = []
	unless content.is_a? Array
		content = Array[content]
	end
	content.each do |result|
		begin
			output << case result["resource_name"]
				when 'end_user'
					User.new(result)
				when 'currency'
					Currency.new(result)
				when 'named_transaction'
				  NamedTransaction.new(result)
				when 'named_transaction_group'
					NamedTransactionGroup.new(result)
				else
					result
			end
		rescue
			debugger
		end
	end
	
	output.length == 1 ? output.first : output
end

#perform_request(*args) ⇒ Object

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/big-door.rb', line 54

def perform_request(*args)
	request_type, action, args = args
	raise BigDoorError, "Unknown request type" unless ['get', 'post', 'put', 'delete'].include? request_type

	query = args
	params = {}
	query = {} if (query.is_a? Array and query.empty?) or query.nil?
	
	action << '/' + query.delete(:id).to_s if query.has_key? :id

	if request_type == 'delete'
		query = {:delete_token => SecureRandom.hex}
	elsif ['post', 'put'].include?(request_type)
		params[:body] = query
		params[:body][:time] = "%.2f" % Time.now.to_f
		params[:body][:token] = SecureRandom.hex
		query = {}
	end

	path = [BASE_URI, ClassMethods.app_key, action].join('/')
	params[:query] = query
	params[:query][:time] = params[:body][:time] rescue "%.2f" % Time.now.to_f
	params[:query][:sig] = calculate_sha2_hash(path, params)
	params[:query][:format] = 'json'
	url = [BASE_URL, path].join('/')
	parse_response(BigDoor::Request.send(request_type, url, params))
end