iframely 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91587997c33a71850459d7c564055faa00320ec7
4
- data.tar.gz: c8bc80f9a894d87612160adff95ba36b514e27e8
3
+ metadata.gz: b10b42b4cfb1617beb31f872e31014532e32fe7f
4
+ data.tar.gz: f0b06bc1f36bd9700339fddeeb9da96d6535a9a4
5
5
  SHA512:
6
- metadata.gz: e20e699477de580cd8dc67c5341889920bf1519318d81dac8e7e15a19b0ae543993754d43f0be1a22213b5beb42e9f0a693b140e9bac29465fa49ba0bbced4e2
7
- data.tar.gz: bf65427d99ac61c66163afb5db3aad7fa261f66ad559af83e845e7c0720265f6725731a7b74470a2e731b95c3dbde01f2e30964829afeb821daeaed5fc902f79
6
+ metadata.gz: 225cfb8074185548f48fd82012dfb8be19e38ca3de6d61809d8b8521f0faa5b9ab73adee0e9796819fb7eca46bb1ccb4d9a0476ec177e08256f1450246a87f75
7
+ data.tar.gz: 5c15a3ea52ac36197207af9da0b2baae8a525dffcc211df557bc8d0d87213e39aa1d7d936af78d60fca2a744e55e4c080cca10a80a0ac11054cc9cb147d00406
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0
4
+
5
+ notifications:
6
+ email: false
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["danil@brandymint.ru"]
11
11
  spec.summary = %q{iframe.ly ruby client}
12
12
  #spec.description = %q{TODO: Write a longer description. Optional.}
13
- spec.homepage = "http://iframe.ly"
13
+ spec.homepage = 'https://github.com/BrandyMint/iframely'
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -3,22 +3,32 @@ require 'json'
3
3
 
4
4
  module Iframely
5
5
  class Requester
6
- def initialize api_key: nil, iframely_url: IFRAMELY_API_URL, oembed_url: OEMBED_API_URL
7
- @iframely_url = iframely_url or raise "No iframely_url specified"
8
- @oembed_url = oembed_url or raise "No oembed_url specified"
9
- @api_key = api_key or raise "No api_key specified"
10
- end
6
+ CACHE_KEY_PREFIX = 'iframely:'
7
+ attr_accessor :iframely_url, :oembed_url, :api_key, :cache, :cache_options
11
8
 
12
- def get_json embed_url
13
- response = iframely_connection.get do |req|
14
- req.params['api_key'] = api_key
15
- req.params['url'] = embed_url
9
+ def initialize api_key: nil, cache: nil, cache_options: {}, iframely_url: IFRAMELY_API_URL, oembed_url: OEMBED_API_URL
10
+ @iframely_url = iframely_url or raise "No iframely_url specified"
11
+ @oembed_url = oembed_url or raise "No oembed_url specified"
12
+ @api_key = api_key or raise "No api_key specified"
13
+ @cache = cache
14
+ if cache
15
+ raise "cache must be a ActiveSupport::Cache::Store" unless defined?(ActiveSupport::Cache::Store) && cache.is_a?(ActiveSupport::Cache::Store)
16
16
  end
17
-
18
- return JSON.parse response.body
17
+ @cache_options = cache_options
19
18
  end
20
19
 
21
20
  def get_iframely embed_url
21
+ fetch cache_key(:iframely, embed_url) do
22
+ response = iframely_connection.get do |req|
23
+ req.params['api_key'] = api_key
24
+ req.params['url'] = embed_url
25
+ end
26
+
27
+ JSON.parse response.body
28
+ end
29
+ end
30
+
31
+ def get_iframely_model embed_url
22
32
  json = get_json embed_url
23
33
  if json.has_key? 'error'
24
34
  raise Iframely::Error, json['error']
@@ -28,17 +38,30 @@ module Iframely
28
38
  end
29
39
 
30
40
  def get_oembed embed_url
31
- response = oembed_connection.get do |req|
32
- req.params['api_key'] = api_key
33
- req.params['url'] = embed_url
34
- end
41
+ fetch cache_key(:oembed, embed_url) do
42
+ response = oembed_connection.get do |req|
43
+ req.params['api_key'] = api_key
44
+ req.params['url'] = embed_url
45
+ end
35
46
 
36
- return JSON.parse response.body
47
+ JSON.parse response.body
48
+ end
37
49
  end
38
50
 
39
51
  private
40
52
 
41
- attr_reader :iframely_url, :oembed_url, :api_key
53
+ def cache_key type, url
54
+ CACHE_KEY_PREFIX + type.to_s + ':' + url.to_s
55
+ return CACHE_KEY_PREFIX
56
+ end
57
+
58
+ def fetch cache_key, &block
59
+ if cache
60
+ cache.fetch cache_key, &block
61
+ else
62
+ block.call
63
+ end
64
+ end
42
65
 
43
66
  def oembed_connection
44
67
  @oembed_connection ||= Faraday.new(:url => oembed_url) do |faraday|
@@ -1,3 +1,3 @@
1
1
  module Iframely
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -12,7 +12,7 @@ class IframelyRequesterTers < Minitest::Test
12
12
  stub_request(:get, Iframely::IFRAMELY_API_URL + "?api_key=some_key&url=some_url").
13
13
  to_return(:status => 200, :body => "{}")
14
14
 
15
- @iframely.get_json EMBED_URL
15
+ @iframely.get_iframely EMBED_URL
16
16
  end
17
17
 
18
18
  def test_request_oembed
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iframely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danil Pismenny
@@ -116,7 +116,7 @@ files:
116
116
  - lib/iframely/version.rb
117
117
  - test/iframely_requester_test.rb
118
118
  - test/test_helper.rb
119
- homepage: http://iframe.ly
119
+ homepage: https://github.com/BrandyMint/iframely
120
120
  licenses:
121
121
  - MIT
122
122
  metadata: {}