infogram-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 968b32a5699c924baebf97495b400460f3c9239f
4
- data.tar.gz: c3fe53dd1921cdd715ef9c16df1355cbb41c9854
3
+ metadata.gz: 673b209eab1d0ab5e1cbc5e37c1a0920718e7ca4
4
+ data.tar.gz: a21a7942c9f0371b6ae3a4287a14d136949e6463
5
5
  SHA512:
6
- metadata.gz: 88cdb908c047d268536ea7a7bb0587aec1a29f80842297ab8846b16a96d1db26e2cf143d8b79747372a3c08bcb4716d9a33d8dfa9fcd5ddf11768464747de914
7
- data.tar.gz: eef64086dfae9252b2c716b31b2b49dc0adb5d20040225c36c13a4e1ac273ca948a9f69e962b1932c1d3d400bfa0c7f8bdb0ddf604e8d5fdc5a06cba1915d8ff
6
+ metadata.gz: 42c6e5cbe3ebef37551ed03144061ffadb3bb71177fd32c9002ac9c4097cd6491391e44ba45d020dc54c31e11aed435106b943fbc81b8e569d0c43817d5425d7
7
+ data.tar.gz: 0dd4da9af12eff3b18dc916546208709934d8585dd296eb213d790b8ba8e23adc3da5d5c158d9110768155d0fc684dd0cccaa3b9fa525e26eb1968bf56d7a9d6
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  ## Usage
22
22
  ```ruby
23
23
  infogram = Infogram.new('API_KEY', 'API_SECRET')
24
- client.get_themes
24
+ infogram.get_themes
25
25
  ```
26
26
  ## Example response
27
27
  ```json
@@ -31,11 +31,6 @@ client.get_themes
31
31
  "title": "twitter",
32
32
  "thumb": "https://infogr.am/i/templates/61/twitter-thumbnail-small.png"
33
33
  },
34
- {
35
- "id": 44,
36
- "title": "Megaphone",
37
- "thumb": "https://infogr.am/i/templates/S/PRO-megaphone.png"
38
- },
39
34
  {
40
35
  "id": 34,
41
36
  "title": "Asketic-new",
@@ -4,12 +4,12 @@ $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.3'
7
+ s.version = '0.0.4'
8
8
  s.authors = ['Maksim Berjoza']
9
- s.email = ['torbjon@gmail.com']
9
+ s.email = ['maksim@infogr.am']
10
10
  s.summary = %q{Infogr.am Ruby SDK}
11
11
  s.description = %q{Ruby library for Infogr.am}
12
- s.homepage = ''
12
+ s.homepage = 'https://github.com/infogram/infogram-ruby'
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files -z`.split("\x0")
@@ -3,20 +3,18 @@ require 'json'
3
3
  require 'cgi'
4
4
 
5
5
  class Infogram
6
- API_URL = 'https://infogr.am/service/v1'
7
-
8
6
  attr_accessor :api_key, :api_secret, :api_url
9
7
 
10
8
  def initialize(api_key, api_secret)
11
9
  @api_key = api_key
12
10
  @api_secret = api_secret
13
- @api_url = API_URL
11
+ @api_url = 'https://infogr.am/service/v1'
14
12
  end
15
13
 
16
14
  def decode_params(params)
17
15
  params.keys.sort.map{ |k|
18
- value = (k.to_s == 'content') ? url_escaping(params[k].to_json) : params[k]
19
- "#{k}=#{value}"
16
+ value = ("#{k}" == 'content') ? params[k].to_json : params[k]
17
+ "#{k}=#{url_escaping(value)}"
20
18
  }.join('&')
21
19
  end
22
20
 
@@ -27,29 +25,21 @@ class Infogram
27
25
  end
28
26
 
29
27
  def url_escaping(string)
30
- CGI.escape(string).gsub('+', '%20')
28
+ CGI.escape(string.to_s).gsub('+', '%20')
31
29
  end
32
30
 
33
- # themes
34
31
  def get_themes(opts={})
35
32
  opts[:api_key] = @api_key
36
33
  opts[:api_sig] = signature('GET', 'themes', opts)
37
34
  HTTParty.get("#{@api_url}/themes", query: opts)
38
35
  end
39
36
 
40
- # infographics
41
37
  def get_infographics(opts={})
42
38
  opts[:api_key] = @api_key
43
- opts[:api_sig] = signature('GET', "infographics", opts)
39
+ opts[:api_sig] = signature('GET', 'infographics', opts)
44
40
  HTTParty.get("#{@api_url}/infographics", query: opts)
45
41
  end
46
42
 
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
-
53
43
  def create_infographic(opts={})
54
44
  opts[:api_key] = @api_key
55
45
  opts[:api_sig] = signature('POST', 'infographics', opts)
@@ -1,4 +1,4 @@
1
- require 'infogram-ruby'
1
+ require 'infogram'
2
2
  require 'rspec'
3
3
  require 'webmock/rspec'
4
4
 
@@ -13,19 +13,3 @@ 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,34 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infogram-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maksim Berjoza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '1.8'
69
69
  description: Ruby library for Infogr.am
70
70
  email:
71
- - torbjon@gmail.com
71
+ - maksim@infogr.am
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -81,13 +81,10 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - infogram-ruby.gemspec
84
- - lib/infogram-ruby.rb
85
- - spec/fixtures/infographic.json
86
- - spec/fixtures/infographics.json
87
- - spec/fixtures/themes.json
84
+ - lib/infogram.rb
88
85
  - spec/helper.rb
89
- - spec/infogram-ruby_spec.rb
90
- homepage: ''
86
+ - spec/infogram_spec.rb
87
+ homepage: https://github.com/infogram/infogram-ruby
91
88
  licenses:
92
89
  - MIT
93
90
  metadata: {}
@@ -112,8 +109,5 @@ signing_key:
112
109
  specification_version: 4
113
110
  summary: Infogr.am Ruby SDK
114
111
  test_files:
115
- - spec/fixtures/infographic.json
116
- - spec/fixtures/infographics.json
117
- - spec/fixtures/themes.json
118
112
  - spec/helper.rb
119
- - spec/infogram-ruby_spec.rb
113
+ - spec/infogram_spec.rb
@@ -1,10 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- ]
@@ -1,17 +0,0 @@
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
- ]
@@ -1,63 +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 (: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