Module: BOTR::API

Included in:
Object, Object
Defined in:
lib/botr/api/api.rb

Instance Method Summary collapse

Instance Method Details

#api_call_classObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/botr/api/api.rb', line 38

def api_call_class
	if defined? call_class
		call_class
	elsif defined? self.class.call_class
		self.class.call_class
	elsif (defined? self.name) && (self.class.name == "Class")	# We are in a class.
		klass, subclass = self.name.scan(/([[:upper:]][[:lower:]]+)/).flatten
		subclass ? "#{klass}s/#{subclass}s".downcase : "#{klass}s".downcase
	else	# We are in an instance.
		klass, subclass = self.class.name.scan(/([[:upper:]][[:lower:]]+)/).flatten
		subclass ? "#{klass}s/#{subclass}s".downcase : "#{klass}s".downcase
	end
end

#api_formatObject



17
18
19
# File 'lib/botr/api/api.rb', line 17

def api_format
	"json"
end

#api_keyObject



21
22
23
# File 'lib/botr/api/api.rb', line 21

def api_key
	BOTR.configuration.api_key || BOTR::API_KEY
end

#api_nonceObject

Return an 8-digit random number.



30
31
32
# File 'lib/botr/api/api.rb', line 30

def api_nonce
	8.times.map { [*'0'..'9'].sample }.join
end

#api_protocolObject



5
6
7
# File 'lib/botr/api/api.rb', line 5

def api_protocol
	BOTR.configuration.protocol || "https"
end

#api_secret_keyObject



34
35
36
# File 'lib/botr/api/api.rb', line 34

def api_secret_key
	BOTR.configuration.secret_key || BOTR::SECRET_KEY
end

#api_serverObject



9
10
11
# File 'lib/botr/api/api.rb', line 9

def api_server
	BOTR.configuration.server || "api.bitsontherun.com"
end

#api_timestampObject



25
26
27
# File 'lib/botr/api/api.rb', line 25

def api_timestamp
	Time.now.to_i
end

#api_url(api_method = "") ⇒ Object



68
69
70
# File 'lib/botr/api/api.rb', line 68

def api_url(api_method = "")
	"#{api_protocol}://#{api_server}/#{api_version}/#{api_call_class}/#{api_method}"
end

#api_versionObject



13
14
15
# File 'lib/botr/api/api.rb', line 13

def api_version
	"v1"
end

#progress_url(callback) ⇒ Object



77
78
79
# File 'lib/botr/api/api.rb', line 77

def progress_url(callback)
	"#{upload_protocol}://#{upload_address}/progress?token=#{upload_token}&callback=#{callback}"
end

#upload_addressObject



56
57
58
# File 'lib/botr/api/api.rb', line 56

def upload_address
	@link["address"] || "upload.bitsontherun.com"
end

#upload_keyObject



60
61
62
# File 'lib/botr/api/api.rb', line 60

def upload_key
	@link["query"]["key"] || upload_key
end

#upload_protocolObject



52
53
54
# File 'lib/botr/api/api.rb', line 52

def upload_protocol
	@link["protocol"] || "http"
end

#upload_tokenObject



64
65
66
# File 'lib/botr/api/api.rb', line 64

def upload_token
	@link["query"]["token"] || upload_token
end

#upload_urlObject



72
73
74
75
# File 'lib/botr/api/api.rb', line 72

def upload_url
	"#{upload_protocol}://#{upload_address}/#{api_version}/#{api_call_class}/upload"
	# "http://httpbin.org/post"
end