iframely 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/iframely.gemspec +1 -1
- data/lib/iframely/requester.rb +40 -17
- data/lib/iframely/version.rb +1 -1
- data/test/iframely_requester_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b10b42b4cfb1617beb31f872e31014532e32fe7f
|
4
|
+
data.tar.gz: f0b06bc1f36bd9700339fddeeb9da96d6535a9a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225cfb8074185548f48fd82012dfb8be19e38ca3de6d61809d8b8521f0faa5b9ab73adee0e9796819fb7eca46bb1ccb4d9a0476ec177e08256f1450246a87f75
|
7
|
+
data.tar.gz: 5c15a3ea52ac36197207af9da0b2baae8a525dffcc211df557bc8d0d87213e39aa1d7d936af78d60fca2a744e55e4c080cca10a80a0ac11054cc9cb147d00406
|
data/.travis.yml
CHANGED
data/iframely.gemspec
CHANGED
@@ -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 =
|
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")
|
data/lib/iframely/requester.rb
CHANGED
@@ -3,22 +3,32 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Iframely
|
5
5
|
class Requester
|
6
|
-
|
7
|
-
|
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
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
47
|
+
JSON.parse response.body
|
48
|
+
end
|
37
49
|
end
|
38
50
|
|
39
51
|
private
|
40
52
|
|
41
|
-
|
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|
|
data/lib/iframely/version.rb
CHANGED
@@ -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.
|
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.
|
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:
|
119
|
+
homepage: https://github.com/BrandyMint/iframely
|
120
120
|
licenses:
|
121
121
|
- MIT
|
122
122
|
metadata: {}
|