Class: Iframely::Requester
- Inherits:
-
Object
- Object
- Iframely::Requester
- Defined in:
- lib/iframely/requester.rb
Constant Summary collapse
- CACHE_KEY_PREFIX =
'iframely:'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_options ⇒ Object
Returns the value of attribute cache_options.
-
#iframely_url ⇒ Object
Returns the value of attribute iframely_url.
-
#oembed_url ⇒ Object
Returns the value of attribute oembed_url.
Instance Method Summary collapse
- #get_iframely_json(embed_url) ⇒ Object
- #get_iframely_model(embed_url) ⇒ Object
- #get_oembed_json(embed_url) ⇒ Object
-
#initialize(api_key: nil, cache: nil, cache_options: {}, iframely_url: IFRAMELY_API_URL, oembed_url: OEMBED_API_URL) ⇒ Requester
constructor
A new instance of Requester.
Constructor Details
#initialize(api_key: nil, cache: nil, cache_options: {}, iframely_url: IFRAMELY_API_URL, oembed_url: OEMBED_API_URL) ⇒ Requester
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/iframely/requester.rb', line 9 def initialize api_key: nil, cache: nil, cache_options: {}, iframely_url: IFRAMELY_API_URL, oembed_url: OEMBED_API_URL @iframely_url = iframely_url or raise "No iframely_url specified" = or raise "No oembed_url specified" @api_key = api_key or raise "No api_key specified" @cache = cache if cache raise "cache must be a ActiveSupport::Cache::Store" unless defined?(ActiveSupport::Cache::Store) && cache.is_a?(ActiveSupport::Cache::Store) end = end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/iframely/requester.rb', line 7 def api_key @api_key end |
#cache ⇒ Object
Returns the value of attribute cache.
7 8 9 |
# File 'lib/iframely/requester.rb', line 7 def cache @cache end |
#cache_options ⇒ Object
Returns the value of attribute cache_options.
7 8 9 |
# File 'lib/iframely/requester.rb', line 7 def end |
#iframely_url ⇒ Object
Returns the value of attribute iframely_url.
7 8 9 |
# File 'lib/iframely/requester.rb', line 7 def iframely_url @iframely_url end |
#oembed_url ⇒ Object
Returns the value of attribute oembed_url.
7 8 9 |
# File 'lib/iframely/requester.rb', line 7 def end |
Instance Method Details
#get_iframely_json(embed_url) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/iframely/requester.rb', line 20 def get_iframely_json fetch cache_key(:iframely, ) do response = iframely_connection.get do |req| req.params['api_key'] = api_key req.params['url'] = end JSON.parse response.body end end |
#get_iframely_model(embed_url) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/iframely/requester.rb', line 31 def get_iframely_model json = get_iframely_json if json.has_key? 'error' raise Iframely::Error, json['error'] else Iframely::Model.build json end end |
#get_oembed_json(embed_url) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/iframely/requester.rb', line 40 def fetch cache_key(:oembed, ) do response = .get do |req| req.params['api_key'] = api_key req.params['url'] = end JSON.parse response.body end end |