infogram-ruby 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -14
- data/README.md +8 -12
- data/infogram-ruby.gemspec +2 -2
- data/lib/{infogram.rb → infogram-ruby.rb} +15 -5
- data/spec/fixtures/infographic.json +10 -0
- data/spec/fixtures/infographics.json +21 -0
- data/spec/fixtures/themes.json +17 -0
- data/spec/helper.rb +17 -1
- data/spec/infogram-ruby_spec.rb +63 -0
- metadata +11 -5
- data/spec/infogram_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a23c1315dba87443649183c1d56c7131b87a9ec
|
4
|
+
data.tar.gz: 61fb6428f5166f7bc551bf8c8a8a50558ac54e4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6928409104494f998b9711bb655fc63f5668cb396bb1e7c64ed8a19635c65e7a8ae818abd215f89ff7e0130b1c56ed9c07425ca1f97a4e97e6e43941a1d4f0
|
7
|
+
data.tar.gz: f6cc7bd51b25d90e05e994e46e276d249755066677486da4540b5129b1134bcf0f2d90c4e148291d6c7f7c2c481424befcb44f7881ad101a5f265604a0a90119
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,25 +4,16 @@ Ruby library for Infogr.am
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'infogram-ruby'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
7
|
$ gem install infogram-ruby
|
20
8
|
|
21
9
|
## Usage
|
22
10
|
```ruby
|
11
|
+
require 'infogram-ruby'
|
12
|
+
|
23
13
|
infogram = Infogram.new('API_KEY', 'API_SECRET')
|
24
14
|
infogram.get_themes
|
25
15
|
```
|
16
|
+
|
26
17
|
## Example response
|
27
18
|
```json
|
28
19
|
[
|
@@ -31,6 +22,11 @@ infogram.get_themes
|
|
31
22
|
"title": "twitter",
|
32
23
|
"thumb": "https://infogr.am/i/templates/61/twitter-thumbnail-small.png"
|
33
24
|
},
|
25
|
+
{
|
26
|
+
"id": 44,
|
27
|
+
"title": "Megaphone",
|
28
|
+
"thumb": "https://infogr.am/i/templates/S/PRO-megaphone.png"
|
29
|
+
},
|
34
30
|
{
|
35
31
|
"id": 34,
|
36
32
|
"title": "Asketic-new",
|
data/infogram-ruby.gemspec
CHANGED
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'infogram-ruby'
|
7
|
-
s.version = '0.0.
|
7
|
+
s.version = '0.0.5'
|
8
8
|
s.authors = ['Maksim Berjoza']
|
9
|
-
s.email = ['
|
9
|
+
s.email = ['torbjon@gmail.com']
|
10
10
|
s.summary = %q{Infogr.am Ruby SDK}
|
11
11
|
s.description = %q{Ruby library for Infogr.am}
|
12
12
|
s.homepage = 'https://github.com/infogram/infogram-ruby'
|
@@ -3,18 +3,20 @@ require 'json'
|
|
3
3
|
require 'cgi'
|
4
4
|
|
5
5
|
class Infogram
|
6
|
+
API_URL = 'https://infogr.am/service/v1'
|
7
|
+
|
6
8
|
attr_accessor :api_key, :api_secret, :api_url
|
7
9
|
|
8
10
|
def initialize(api_key, api_secret)
|
9
11
|
@api_key = api_key
|
10
12
|
@api_secret = api_secret
|
11
|
-
@api_url =
|
13
|
+
@api_url = API_URL
|
12
14
|
end
|
13
15
|
|
14
16
|
def decode_params(params)
|
15
17
|
params.keys.sort.map{ |k|
|
16
|
-
value = (
|
17
|
-
"#{k}=#{
|
18
|
+
value = (k.to_s == 'content') ? url_escaping(params[k].to_json) : params[k]
|
19
|
+
"#{k}=#{value}"
|
18
20
|
}.join('&')
|
19
21
|
end
|
20
22
|
|
@@ -25,21 +27,29 @@ class Infogram
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def url_escaping(string)
|
28
|
-
CGI.escape(string
|
30
|
+
CGI.escape(string).gsub('+', '%20')
|
29
31
|
end
|
30
32
|
|
33
|
+
# themes
|
31
34
|
def get_themes(opts={})
|
32
35
|
opts[:api_key] = @api_key
|
33
36
|
opts[:api_sig] = signature('GET', 'themes', opts)
|
34
37
|
HTTParty.get("#{@api_url}/themes", query: opts)
|
35
38
|
end
|
36
39
|
|
40
|
+
# infographics
|
37
41
|
def get_infographics(opts={})
|
38
42
|
opts[:api_key] = @api_key
|
39
|
-
opts[:api_sig] = signature('GET',
|
43
|
+
opts[:api_sig] = signature('GET', "infographics", opts)
|
40
44
|
HTTParty.get("#{@api_url}/infographics", query: opts)
|
41
45
|
end
|
42
46
|
|
47
|
+
def get_infographic(id, opts={})
|
48
|
+
opts[:api_key] = @api_key
|
49
|
+
opts[:api_sig] = signature('GET', "infographics/#{id}", opts)
|
50
|
+
HTTParty.get("#{@api_url}/infographics/#{id}", query: opts)
|
51
|
+
end
|
52
|
+
|
43
53
|
def create_infographic(opts={})
|
44
54
|
opts[:api_key] = @api_key
|
45
55
|
opts[:api_sig] = signature('POST', 'infographics', opts)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"id": "d819d9b7-67fb-40ec-9400-d63cc209aea8",
|
3
|
+
"title": "sample infographic 2",
|
4
|
+
"theme_id": 32,
|
5
|
+
"published": true,
|
6
|
+
"thumbnail_url": "https://s3-eu-west-1.amazonaws.com/infogram-thumbs-200/d819d9b7-67fb-40ec-9400-d63cc209aea8.jpg",
|
7
|
+
"date_modified": "2014-12-19T09:32:52.000Z",
|
8
|
+
"url": "https://infogr.am/sample-infographic-28",
|
9
|
+
"embed_responsive": "<script id=\"infogram_0_sample-infographic-28\" src=\"//e.infogr.am/js/embed.js?zni\" type=\"text/javascript\"></script><div style=\"width:100%;border-top:1px solid #acacac;padding-top:3px;font-family:Arial;font-size:10px;text-align:center;\"><a target=\"_blank\" href=\"https://infogr.am/sample-infographic-28\" style=\"color:#acacac;text-decoration:none;\">sample infographic 2</a> |<a style=\"color:#acacac;text-decoration:none;\" href=\"https://infogr.am\" target=\"_blank\">Create infographics</a></div>"
|
10
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "309b6f66-83d2-437e-84d3-edb76035b771",
|
4
|
+
"title": "Sample infographic 1",
|
5
|
+
"theme_id": 29,
|
6
|
+
"published": false,
|
7
|
+
"thumbnail_url": "https://s3-eu-west-1.amazonaws.com/infogram-thumbs-200/309b6f66-83d2-437e-84d3-edb76035b771.jpg",
|
8
|
+
"date_modified": "2014-12-09T13:28:36.000Z",
|
9
|
+
"user_profile": "infogram_demo"
|
10
|
+
}, {
|
11
|
+
"id": "d819d9b7-67fb-40ec-9400-d63cc209aea8",
|
12
|
+
"title": "sample infographic 2",
|
13
|
+
"theme_id": 32,
|
14
|
+
"published": true,
|
15
|
+
"thumbnail_url": "https://s3-eu-west-1.amazonaws.com/infogram-thumbs-200/d819d9b7-67fb-40ec-9400-d63cc209aea8.jpg",
|
16
|
+
"date_modified": "2014-12-19T09:32:52.000Z",
|
17
|
+
"user_profile": "infogram_demo",
|
18
|
+
"url": "https://infogr.am/sample-infographic-28",
|
19
|
+
"embed_responsive": "<script id=\"infogram_0_sample-infographic-28\" src=\"//e.infogr.am/js/embed.js?xvj\" type=\"text/javascript\"></script><div style=\"width:100%;border-top:1px solid #acacac;padding-top:3px;font-family:Arial;font-size:10px;text-align:center;\"><a target=\"_blank\" href=\"https://infogr.am/sample-infographic-28\" style=\"color:#acacac;text-decoration:none;\">sample infographic 2</a> |<a style=\"color:#acacac;text-decoration:none;\" href=\"https://infogr.am\" target=\"_blank\">Create infographics</a></div>"
|
20
|
+
}
|
21
|
+
]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id":61,
|
4
|
+
"title":"twitter",
|
5
|
+
"thumbnail_url":"https://infogr.am/i/templates/61/twitter-thumbnail-small.png"
|
6
|
+
},
|
7
|
+
{
|
8
|
+
"id":44,
|
9
|
+
"title":"Megaphone",
|
10
|
+
"thumbnail_url":"https://infogr.am/i/templates/S/PRO-megaphone.png"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"id":34,
|
14
|
+
"title":"Asketic-new",
|
15
|
+
"thumbnail_url":"https://infogr.am/i/templates/S/asketic-black.png"
|
16
|
+
}
|
17
|
+
]
|
data/spec/helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'infogram'
|
1
|
+
require 'infogram-ruby'
|
2
2
|
require 'rspec'
|
3
3
|
require 'webmock/rspec'
|
4
4
|
|
@@ -13,3 +13,19 @@ end
|
|
13
13
|
def infogram_client(key, secret)
|
14
14
|
Infogram.new(key, secret)
|
15
15
|
end
|
16
|
+
|
17
|
+
def fixture(file)
|
18
|
+
File.read('spec/fixtures/' + file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def with_fixture(file)
|
22
|
+
{ body: fixture(file), headers: { content_type: 'application/json; charset=utf-8' } }
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_get(path)
|
26
|
+
stub_request(:get, /.*#{Infogram::API_URL + '/' + path}*/)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_post(path)
|
30
|
+
stub_request(:post, /.*#{Infogram::API_URL + '/' + path}*/)
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'Infogram' do
|
4
|
+
let (:api_key) { 'nMECGhmHe9' }
|
5
|
+
let (:api_secret) { 'da5xoLrCCx' }
|
6
|
+
let (:client) { infogram_client(api_key, api_secret) }
|
7
|
+
let (:params) { {
|
8
|
+
content: [
|
9
|
+
{
|
10
|
+
type: 'h1',
|
11
|
+
text: 'Hello infogr.am'
|
12
|
+
}
|
13
|
+
],
|
14
|
+
theme_id: 45,
|
15
|
+
publish: false,
|
16
|
+
title: 'Hello'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
context 'Signature' do
|
21
|
+
let (:encoded_params) { 'api_key=nMECGhmHe9&content=%5B%7B%22type%22%3A%22h1%22%2C%22text%22%3A%22Hello%20infogr.am%22%7D%5D&publish=false&theme_id=45&title=Hello' }
|
22
|
+
|
23
|
+
it 'should encode params' do
|
24
|
+
params[:api_key] = api_key
|
25
|
+
expect(client.decode_params(params)).to eq(encoded_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should generate signature' do
|
29
|
+
params[:api_key] = api_key
|
30
|
+
signature = client.signature('post', 'infographics', params)
|
31
|
+
expect(signature).to eq('bqwCqAk1TWDYNy3eqV0BiNuIERQ=')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'Themes' do
|
36
|
+
it 'should return themes list' do
|
37
|
+
stub_get('themes').to_return(with_fixture('themes.json'))
|
38
|
+
themes = client.get_themes()
|
39
|
+
expect(themes[0]['id']).to eq(61)
|
40
|
+
expect(themes[1]['title']).to eq('Megaphone')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'Infographic' do
|
45
|
+
it 'GET infographics' do
|
46
|
+
stub_get('infographics').to_return(with_fixture('infographics.json'))
|
47
|
+
ig = client.get_infographics
|
48
|
+
expect(ig[1]['id']).to eq('d819d9b7-67fb-40ec-9400-d63cc209aea8')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'GET infographics/:id' do
|
52
|
+
stub_get('infographics').to_return(with_fixture('infographic.json'))
|
53
|
+
ig = client.get_infographic('d819d9b7-67fb-40ec-9400-d63cc209aea8')
|
54
|
+
expect(ig['title']).to eq('sample infographic 2')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'POST infographics' do
|
58
|
+
stub_post('infographics').to_return(with_fixture('infographic.json'))
|
59
|
+
ig = client.create_infographic(params)
|
60
|
+
expect(ig['title']).to eq('sample infographic 2')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infogram-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maksim Berjoza
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
version: '1.8'
|
69
69
|
description: Ruby library for Infogr.am
|
70
70
|
email:
|
71
|
-
-
|
71
|
+
- torbjon@gmail.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -81,9 +81,12 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- infogram-ruby.gemspec
|
84
|
-
- lib/infogram.rb
|
84
|
+
- lib/infogram-ruby.rb
|
85
|
+
- spec/fixtures/infographic.json
|
86
|
+
- spec/fixtures/infographics.json
|
87
|
+
- spec/fixtures/themes.json
|
85
88
|
- spec/helper.rb
|
86
|
-
- spec/
|
89
|
+
- spec/infogram-ruby_spec.rb
|
87
90
|
homepage: https://github.com/infogram/infogram-ruby
|
88
91
|
licenses:
|
89
92
|
- MIT
|
@@ -109,5 +112,8 @@ signing_key:
|
|
109
112
|
specification_version: 4
|
110
113
|
summary: Infogr.am Ruby SDK
|
111
114
|
test_files:
|
115
|
+
- spec/fixtures/infographic.json
|
116
|
+
- spec/fixtures/infographics.json
|
117
|
+
- spec/fixtures/themes.json
|
112
118
|
- spec/helper.rb
|
113
|
-
- spec/
|
119
|
+
- spec/infogram-ruby_spec.rb
|
data/spec/infogram_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'Infogram' do
|
4
|
-
let (:api_key) { 'nMECGhmHe9' }
|
5
|
-
let (:api_secret) { 'da5xoLrCCx' }
|
6
|
-
let (:client) { infogram_client(api_key, api_secret) }
|
7
|
-
let (:encoded_params) { 'content=%5B%7B%22type%22%3A%22h1%22%2C%22text%22%3A%22Hello%20infogr.am%22%7D%5D&key=nMECGhmHe9&publish=false&template=45&title=Hello' }
|
8
|
-
let (:params) { {
|
9
|
-
template: 45,
|
10
|
-
content: [
|
11
|
-
{
|
12
|
-
type: 'h1',
|
13
|
-
text: 'Hello infogr.am'
|
14
|
-
}
|
15
|
-
],
|
16
|
-
key: api_key,
|
17
|
-
publish: false,
|
18
|
-
title: 'Hello'
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
it 'should encode params' do
|
23
|
-
expect(client.decode_params(params)).to eq(encoded_params)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should generate signature' do
|
27
|
-
signature = client.signature('post', 'infographics', params)
|
28
|
-
expect(signature).to eq('nI2LXdDhKNf7mtdgCHflrcMSluY=')
|
29
|
-
end
|
30
|
-
|
31
|
-
# it 'should return themes list' do
|
32
|
-
# client.get_themes()
|
33
|
-
# end
|
34
|
-
end
|