Class: Urlbox::Client
- Inherits:
-
Object
- Object
- Urlbox::Client
- Defined in:
- lib/urlbox/client.rb
Constant Summary collapse
- BASE_API_URL =
'https://api.urlbox.io/v1/'.freeze
- POST_END_POINT =
'render'.freeze
Instance Method Summary collapse
- #delete(options) ⇒ Object
- #generate_url(options) ⇒ Object
- #get(options) ⇒ Object
- #head(options) ⇒ Object
-
#initialize(api_key: nil, api_secret: nil, api_host_name: nil) ⇒ Client
constructor
A new instance of Client.
- #post(options) ⇒ Object
Constructor Details
#initialize(api_key: nil, api_secret: nil, api_host_name: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/urlbox/client.rb', line 9 def initialize(api_key: nil, api_secret: nil, api_host_name: nil) if api_key.nil? && ENV['URLBOX_API_KEY'].nil? raise Urlbox::Error, "Missing api_key or ENV['URLBOX_API_KEY'] not set" end @api_key = api_key || ENV['URLBOX_API_KEY'] @api_secret = api_secret || ENV['URLBOX_API_SECRET'] @base_api_url = init_base_api_url(api_host_name) end |
Instance Method Details
#delete(options) ⇒ Object
23 24 25 26 |
# File 'lib/urlbox/client.rb', line 23 def delete() , format = () HTTP.delete("#{@base_api_url}#{@api_key}/#{format}?#{processed_options}") end |
#generate_url(options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/urlbox/client.rb', line 48 def generate_url() , format = () if @api_secret "#{@base_api_url}" \ "#{@api_key}/#{token(processed_options)}/#{format}" \ "?#{processed_options}" else "#{@base_api_url}" \ "#{@api_key}/#{format}" \ "?#{processed_options}" end end |
#get(options) ⇒ Object
19 20 21 |
# File 'lib/urlbox/client.rb', line 19 def get() HTTP.timeout(100).follow.get(generate_url()) end |
#head(options) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/urlbox/client.rb', line 28 def head() , format = () HTTP.timeout(100) .follow .head("#{@base_api_url}#{@api_key}/#{format}?#{processed_options}") end |
#post(options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/urlbox/client.rb', line 35 def post() raise Urlbox::Error, Urlbox::Error. if @api_secret.nil? unless .key?(:webhook_url) warn('webhook_url not supplied, you will need to poll the statusUrl in order to get your result') end , _format = () HTTP.timeout(5) .headers('Content-Type': 'application/json', 'Authorization': "Bearer #{@api_secret}") .post("#{@base_api_url}#{POST_END_POINT}", json: ) end |