Class: Ovh::Application
- Inherits:
-
Object
- Object
- Ovh::Application
- Defined in:
- lib/ovh/application.rb,
lib/ovh/configuration.rb
Defined Under Namespace
Classes: Configuration
Instance Method Summary collapse
- #call(method, path, data: {}, need_auth: true, headers: {}) ⇒ Object
- #configuration ⇒ Object
- #delete(path, need_auth: true, headers: {}) ⇒ Object
- #get(path, need_auth: true, headers: {}) ⇒ Object
-
#initialize {|configuration| ... } ⇒ Application
constructor
A new instance of Application.
- #post(path, data: {}, need_auth: true, headers: {}) ⇒ Object
- #put(path, data: {}, need_auth: true, headers: {}) ⇒ Object
- #time_delta! ⇒ Object
Constructor Details
#initialize {|configuration| ... } ⇒ Application
Returns a new instance of Application.
9 10 11 12 13 |
# File 'lib/ovh/application.rb', line 9 def initialize yield(configuration) if block_given? @sha1 = OpenSSL::Digest.new('sha1') @time_delta = 0 end |
Instance Method Details
#call(method, path, data: {}, need_auth: true, headers: {}) ⇒ Object
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 |
# File 'lib/ovh/application.rb', line 35 def call(method, path, data: {}, need_auth: true, headers: {}) raise InvalidHTTPMethod, "invalid http method #{method}" unless API_HTTP_METHODS.include?(method) ts = (Time.now.to_i + @time_delta).to_s url = compute_url(path) raise InvalidKey, 'ApplicationKey is required !' unless configuration.application_key headers['X-Ovh-Application'] = configuration.application_key if data.empty? body = '' else headers['Content-type'] = 'application/json' body = data.to_json end if need_auth raise InvalidKey, 'Consumer is required !' unless configuration.consumer_key headers['X-Ovh-Consumer'] = configuration.consumer_key headers['X-Ovh-Timestamp'] = ts headers['X-Ovh-Signature'] = compute_signature(method, url, body, ts) end do_request(method, url, body:, headers:) end |
#configuration ⇒ Object
15 16 17 |
# File 'lib/ovh/application.rb', line 15 def configuration(&) @configuration ||= Configuration.new(&) end |
#delete(path, need_auth: true, headers: {}) ⇒ Object
31 32 33 |
# File 'lib/ovh/application.rb', line 31 def delete(path, need_auth: true, headers: {}) call(:delete, path, need_auth:, headers:) end |
#get(path, need_auth: true, headers: {}) ⇒ Object
19 20 21 |
# File 'lib/ovh/application.rb', line 19 def get(path, need_auth: true, headers: {}) call(:get, path, need_auth:, headers:) end |
#post(path, data: {}, need_auth: true, headers: {}) ⇒ Object
27 28 29 |
# File 'lib/ovh/application.rb', line 27 def post(path, data: {}, need_auth: true, headers: {}) call(:post, path, data:, need_auth:, headers:) end |
#put(path, data: {}, need_auth: true, headers: {}) ⇒ Object
23 24 25 |
# File 'lib/ovh/application.rb', line 23 def put(path, data: {}, need_auth: true, headers: {}) call(:put, path, data:, need_auth:, headers:) end |
#time_delta! ⇒ Object
63 64 65 66 |
# File 'lib/ovh/application.rb', line 63 def time_delta! server_ts = get('/auth/time', need_auth: false).to_i @time_delta = server_ts - Time.now.to_i end |