Class: Oembedr::Client
- Inherits:
-
Object
- Object
- Oembedr::Client
- Defined in:
- lib/oembedr/client.rb
Instance Attribute Summary collapse
-
#parsed_url ⇒ Object
Returns the value of attribute parsed_url.
-
#resource_url ⇒ Object
Returns the value of attribute resource_url.
Instance Method Summary collapse
-
#connection(options = {}) ⇒ Object
Sets up a Faraday::Connection object.
-
#get(options = {}) ⇒ Object
Requests the oembeddable resource.
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
-
#ready? ⇒ Boolean
Returns a boolean true/false if we can process this request.
Constructor Details
Instance Attribute Details
#parsed_url ⇒ Object
Returns the value of attribute parsed_url.
6 7 8 |
# File 'lib/oembedr/client.rb', line 6 def parsed_url @parsed_url end |
#resource_url ⇒ Object
Returns the value of attribute resource_url.
6 7 8 |
# File 'lib/oembedr/client.rb', line 6 def resource_url @resource_url end |
Instance Method Details
#connection(options = {}) ⇒ Object
Sets up a Faraday::Connection object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/oembedr/client.rb', line 19 def connection = {} = { :headers => { "Accept" => "application/json", "User-Agent" => Oembedr.user_agent }, :url => parsed_url.host }.merge() Faraday.new() do |builder| builder.use Faraday::Request::UrlEncoded builder.use Faraday::Response::ParseJson builder.use Faraday::Response::RaiseError builder.adapter Oembedr.adapter end end |
#get(options = {}) ⇒ Object
Requests the oembeddable resource
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/oembedr/client.rb', line 39 def get = {} additional_params = .delete(:params) || {} connection().get do |req| req.url parsed_url.path req.params = additional_params.merge({ :url => resource_url, :format => "json" }) end end |
#ready? ⇒ Boolean
Returns a boolean true/false if we can process this request
53 54 55 |
# File 'lib/oembedr/client.rb', line 53 def ready? !!parsed_url.host end |