Module: BigDoor::ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_keyObject



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

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



27
28
29
# File 'lib/big-door.rb', line 27

def self.secret_key
	@secret_key
end

Instance Method Details

#parse_out_classes(content) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/big-door.rb', line 31

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)
				when 'named_level'
				  NamedLevel.new(result)
				when 'named_level_collection'
				  NamedLevelCollection.new(result)
				when 'named_award'
				  NamedAward.new(result)
				when 'named_award_collection'
				  NamedAwardCollection.new(result)
				else
					result
			end
		rescue
			debugger
		end
	end
	
	output.length == 1 ? output.first : output
end

#perform_request(*args) ⇒ Object

Raises:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/big-door.rb', line 66

def perform_request(*args)
	request_type, action, args, envelope = args
	envelope = {} unless envelope

	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 = {}
		
		envelope.each_pair do |key, value|
		  params[:body][key] = value
		end
	end
	params.keys.sort!

	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('/')
	
	p request_type
	p url
	p params
	
	parse_response(BigDoor::Request.send(request_type, url, params))
end

#remote_idObject



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

def remote_id
    @id || nil
end