Module: BOTR::API
Instance Method Summary collapse
- #api_call_class ⇒ Object
- #api_format ⇒ Object
- #api_key ⇒ Object
-
#api_nonce ⇒ Object
Return an 8-digit random number.
- #api_protocol ⇒ Object
- #api_secret_key ⇒ Object
- #api_server ⇒ Object
- #api_timestamp ⇒ Object
- #api_url(api_method = "") ⇒ Object
- #api_version ⇒ Object
- #progress_url(callback) ⇒ Object
- #upload_address ⇒ Object
- #upload_key ⇒ Object
- #upload_protocol ⇒ Object
- #upload_token ⇒ Object
- #upload_url ⇒ Object
Instance Method Details
#api_call_class ⇒ Object
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_format ⇒ Object
17 18 19 |
# File 'lib/botr/api/api.rb', line 17 def api_format "json" end |
#api_key ⇒ Object
21 22 23 |
# File 'lib/botr/api/api.rb', line 21 def api_key BOTR.configuration.api_key || BOTR::API_KEY end |
#api_nonce ⇒ Object
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_protocol ⇒ Object
5 6 7 |
# File 'lib/botr/api/api.rb', line 5 def api_protocol BOTR.configuration.protocol || "https" end |
#api_secret_key ⇒ Object
34 35 36 |
# File 'lib/botr/api/api.rb', line 34 def api_secret_key BOTR.configuration.secret_key || BOTR::SECRET_KEY end |
#api_server ⇒ Object
9 10 11 |
# File 'lib/botr/api/api.rb', line 9 def api_server BOTR.configuration.server || "api.bitsontherun.com" end |
#api_timestamp ⇒ Object
25 26 27 |
# File 'lib/botr/api/api.rb', line 25 def 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_version ⇒ Object
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_address ⇒ Object
56 57 58 |
# File 'lib/botr/api/api.rb', line 56 def upload_address @link["address"] || "upload.bitsontherun.com" end |
#upload_key ⇒ Object
60 61 62 |
# File 'lib/botr/api/api.rb', line 60 def upload_key @link["query"]["key"] || upload_key end |
#upload_protocol ⇒ Object
52 53 54 |
# File 'lib/botr/api/api.rb', line 52 def upload_protocol @link["protocol"] || "http" end |
#upload_token ⇒ Object
64 65 66 |
# File 'lib/botr/api/api.rb', line 64 def upload_token @link["query"]["token"] || upload_token end |
#upload_url ⇒ Object
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 |