growviral-keystore 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/growviral/{twitter_account.rb → account.rb} +3 -2
- data/lib/growviral/{setter.rb → account_creator.rb} +9 -8
- data/lib/growviral/account_fetcher.rb +25 -0
- data/lib/growviral/application.rb +15 -0
- data/lib/growviral/application_fetcher.rb +26 -0
- data/lib/growviral/client.rb +8 -4
- data/lib/growviral/keystore/version.rb +1 -1
- data/lib/growviral/keystore.rb +7 -3
- data/test/{setter_test.rb → account_creator_test.rb} +6 -3
- data/test/{getter_test.rb → account_fetcher_test.rb} +8 -5
- data/test/{twitter_account_test.rb → account_test.rb} +2 -2
- data/test/application_fetcher_test.rb +32 -0
- metadata +15 -11
- data/lib/growviral/getter.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c3334ceb931b621425db81adc3a4f897b7564a7
|
4
|
+
data.tar.gz: 98a16717b048e043d236ae374cd60f862de5e388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b9359f8306f37dfb88c8058c3fb4b2ff4f8a20de05164702835cafc6d2c41f481e3794c9b3ae5333644016d117e013f43247c0dea10680b96b461e36fe37c0
|
7
|
+
data.tar.gz: d4e848dfcdcb57278be0fafcfdce98d9de8f0162c5754335e14ddbb26ddef426cc05a26a2138ece9ff39e842cd8701ff4a0d3ecdeb0087e862506dbde67c2304
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module GrowViral
|
2
2
|
module Keystore
|
3
|
-
class
|
4
|
-
attr_reader :uid, :handle, :token, :secret
|
3
|
+
class Account
|
4
|
+
attr_reader :application_id, :uid, :handle, :token, :secret
|
5
5
|
def initialize(data)
|
6
|
+
@application_id = data['application_id']
|
6
7
|
@uid = data['uid']
|
7
8
|
@handle = data['handle']
|
8
9
|
@token = data['token']
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module GrowViral
|
2
2
|
module Keystore
|
3
|
-
class
|
4
|
-
def self.
|
5
|
-
new(*args).
|
3
|
+
class AccountCreator
|
4
|
+
def self.create(*args)
|
5
|
+
new(*args).create
|
6
6
|
end
|
7
7
|
|
8
|
-
attr_reader :handle, :uid, :token, :secret, :config
|
9
|
-
def initialize(handle, uid, token, secret, deps)
|
8
|
+
attr_reader :application_id, :handle, :uid, :token, :secret, :config
|
9
|
+
def initialize(application_id, handle, uid, token, secret, deps)
|
10
|
+
@application_id = application_id
|
10
11
|
@handle = handle
|
11
12
|
@uid = uid
|
12
13
|
@token = token
|
@@ -14,13 +15,13 @@ module GrowViral
|
|
14
15
|
@config = deps[:config]
|
15
16
|
end
|
16
17
|
|
17
|
-
def
|
18
|
+
def create
|
18
19
|
response = Net::HTTP.post_form(uri, form_data)
|
19
|
-
|
20
|
+
Account.new JSON.parse(response.body)
|
20
21
|
end
|
21
22
|
|
22
23
|
def uri
|
23
|
-
@uri ||= URI.parse("#{config.host}/
|
24
|
+
@uri ||= URI.parse("#{config.host}/applications/#{application_id}/accounts/#{handle}")
|
24
25
|
end
|
25
26
|
|
26
27
|
def form_data
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GrowViral
|
2
|
+
module Keystore
|
3
|
+
class AccountFetcher
|
4
|
+
def self.fetch(*args)
|
5
|
+
new(*args).fetch
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :application_id, :handle, :config
|
9
|
+
def initialize(application_id, handle, deps)
|
10
|
+
@application_id = application_id
|
11
|
+
@handle = handle
|
12
|
+
@config = deps[:config]
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch
|
16
|
+
response = Net::HTTP.get_response(uri)
|
17
|
+
Account.new JSON.parse(response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def uri
|
21
|
+
@uri ||= URI.parse("#{config.host}/applications/#{application_id}/accounts/#{handle}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GrowViral
|
2
|
+
module Keystore
|
3
|
+
class Application
|
4
|
+
attr_reader :id, :provider, :name, :token, :secret
|
5
|
+
def initialize(data)
|
6
|
+
@id = data['id']
|
7
|
+
@provider = data['provider']
|
8
|
+
@name = data['name']
|
9
|
+
@token = data['token']
|
10
|
+
@secret = data['secret']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GrowViral
|
2
|
+
module Keystore
|
3
|
+
class ApplicationFetcher
|
4
|
+
def self.fetch(*args)
|
5
|
+
new(*args).fetch
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :provider, :name, :config
|
9
|
+
def initialize(provider, name, deps)
|
10
|
+
@provider = provider
|
11
|
+
@name = name
|
12
|
+
@config = deps[:config]
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch
|
16
|
+
response = Net::HTTP.get_response(uri)
|
17
|
+
Application.new JSON.parse(response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def uri
|
21
|
+
@uri ||= URI.parse("#{config.host}/applications/#{name}?provider=#{provider}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/growviral/client.rb
CHANGED
@@ -7,12 +7,16 @@ module GrowViral
|
|
7
7
|
@config = Configuration.new(env)
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def fetch_application(provider, name)
|
11
|
+
ApplicationFetcher.fetch(provider, name, config: config)
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def fetch_account(app_id, handle)
|
15
|
+
AccountFetcher.fetch(app_id, handle, config: config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_account(app_id, handle, uid, token, secret)
|
19
|
+
AccountCreator.create(app_id, handle, uid, token, secret, config: config)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
data/lib/growviral/keystore.rb
CHANGED
@@ -5,9 +5,13 @@ require 'json'
|
|
5
5
|
require "growviral/keystore/version"
|
6
6
|
require "growviral/client"
|
7
7
|
require "growviral/configuration"
|
8
|
-
|
9
|
-
require "growviral/
|
10
|
-
require "growviral/
|
8
|
+
|
9
|
+
require "growviral/application"
|
10
|
+
require "growviral/application_fetcher"
|
11
|
+
|
12
|
+
require "growviral/account"
|
13
|
+
require "growviral/account_fetcher"
|
14
|
+
require "growviral/account_creator"
|
11
15
|
|
12
16
|
module GrowViral
|
13
17
|
module Keystore
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class AccountCreatorTest < Minitest::Test
|
4
4
|
def test_response_is_correct
|
5
|
+
application_id = 532
|
5
6
|
uid = 1231212
|
6
7
|
handle = "foobar"
|
7
8
|
token = "asdasda"
|
@@ -15,18 +16,20 @@ class SetterTest < Minitest::Test
|
|
15
16
|
}
|
16
17
|
|
17
18
|
output = {
|
19
|
+
"application_id" => application_id,
|
18
20
|
"handle" => handle,
|
19
21
|
"uid" => uid,
|
20
22
|
"token" => token,
|
21
23
|
"secret" => secret
|
22
24
|
}
|
23
25
|
|
24
|
-
uri = URI.parse("http://localhost:3000/
|
26
|
+
uri = URI.parse("http://localhost:3000/applications/#{application_id}/accounts/#{handle}")
|
25
27
|
Net::HTTP.expects(:post_form).with(uri, input).returns(mock(body: output.to_json))
|
26
28
|
|
27
29
|
client = GrowViral::Keystore::Client.new(:development)
|
28
|
-
account = client.
|
30
|
+
account = client.create_account(application_id, handle, uid, token, secret)
|
29
31
|
|
32
|
+
assert_equal application_id, account.application_id
|
30
33
|
assert_equal uid, account.uid
|
31
34
|
assert_equal handle, account.handle
|
32
35
|
assert_equal token, account.token
|
@@ -1,25 +1,28 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class AccountFetcherTest < Minitest::Test
|
4
4
|
def test_response_is_correct
|
5
|
+
application_id = 43
|
5
6
|
uid = 1231212
|
6
7
|
handle = "foobar"
|
7
8
|
token = "asdasda"
|
8
9
|
secret = "2349966adasds"
|
9
10
|
|
10
|
-
|
11
|
+
output = {
|
12
|
+
"application_id" => application_id,
|
11
13
|
"handle" => handle,
|
12
14
|
"uid" => uid,
|
13
15
|
"token" => token,
|
14
16
|
"secret" => secret
|
15
17
|
}
|
16
18
|
|
17
|
-
uri = URI.parse("http://localhost:3000/
|
18
|
-
Net::HTTP.expects(:get_response).with(uri).returns(mock(body:
|
19
|
+
uri = URI.parse("http://localhost:3000/applications/#{application_id}/accounts/#{handle}")
|
20
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
19
21
|
|
20
22
|
client = GrowViral::Keystore::Client.new(:development)
|
21
|
-
account = client.
|
23
|
+
account = client.fetch_account(application_id, handle)
|
22
24
|
|
25
|
+
assert_equal application_id, account.application_id
|
23
26
|
assert_equal uid, account.uid
|
24
27
|
assert_equal handle, account.handle
|
25
28
|
assert_equal token, account.token
|
@@ -2,7 +2,7 @@ require_relative 'test_helper'
|
|
2
2
|
|
3
3
|
module GrowViral
|
4
4
|
module Keystore
|
5
|
-
class
|
5
|
+
class AccountTest < Minitest::Test
|
6
6
|
def test_initializes_corectly
|
7
7
|
uid = 1231212
|
8
8
|
handle = "foobar"
|
@@ -16,7 +16,7 @@ module GrowViral
|
|
16
16
|
"secret" => secret
|
17
17
|
}
|
18
18
|
|
19
|
-
account =
|
19
|
+
account = Account.new(data)
|
20
20
|
assert_equal uid, account.uid
|
21
21
|
assert_equal handle, account.handle
|
22
22
|
assert_equal token, account.token
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ApplicationFetcherTest < Minitest::Test
|
4
|
+
def test_response_is_correct
|
5
|
+
id = 74
|
6
|
+
provider = 'twitter'
|
7
|
+
name = "growviral"
|
8
|
+
token = "asdasda"
|
9
|
+
secret = "2349966adasds"
|
10
|
+
|
11
|
+
output = {
|
12
|
+
"id" => id,
|
13
|
+
"provider" => provider,
|
14
|
+
"name" => name,
|
15
|
+
"token" => token,
|
16
|
+
"secret" => secret
|
17
|
+
}
|
18
|
+
|
19
|
+
uri = URI.parse("http://localhost:3000/applications/#{name}?provider=#{provider}")
|
20
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
21
|
+
|
22
|
+
client = GrowViral::Keystore::Client.new(:development)
|
23
|
+
application = client.fetch_application(provider, name)
|
24
|
+
|
25
|
+
assert_equal id, application.id
|
26
|
+
assert_equal provider, application.provider
|
27
|
+
assert_equal name, application.name
|
28
|
+
assert_equal token, application.token
|
29
|
+
assert_equal secret, application.secret
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growviral-keystore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,17 +80,20 @@ files:
|
|
80
80
|
- README.md
|
81
81
|
- Rakefile
|
82
82
|
- growviral-keystore.gemspec
|
83
|
+
- lib/growviral/account.rb
|
84
|
+
- lib/growviral/account_creator.rb
|
85
|
+
- lib/growviral/account_fetcher.rb
|
86
|
+
- lib/growviral/application.rb
|
87
|
+
- lib/growviral/application_fetcher.rb
|
83
88
|
- lib/growviral/client.rb
|
84
89
|
- lib/growviral/configuration.rb
|
85
|
-
- lib/growviral/getter.rb
|
86
90
|
- lib/growviral/keystore.rb
|
87
91
|
- lib/growviral/keystore/version.rb
|
88
|
-
-
|
89
|
-
-
|
90
|
-
- test/
|
91
|
-
- test/
|
92
|
+
- test/account_creator_test.rb
|
93
|
+
- test/account_fetcher_test.rb
|
94
|
+
- test/account_test.rb
|
95
|
+
- test/application_fetcher_test.rb
|
92
96
|
- test/test_helper.rb
|
93
|
-
- test/twitter_account_test.rb
|
94
97
|
homepage: ''
|
95
98
|
licenses:
|
96
99
|
- MIT
|
@@ -116,8 +119,9 @@ signing_key:
|
|
116
119
|
specification_version: 4
|
117
120
|
summary: A wrapper for the GrowViral keystore functionality.
|
118
121
|
test_files:
|
119
|
-
- test/
|
120
|
-
- test/
|
122
|
+
- test/account_creator_test.rb
|
123
|
+
- test/account_fetcher_test.rb
|
124
|
+
- test/account_test.rb
|
125
|
+
- test/application_fetcher_test.rb
|
121
126
|
- test/test_helper.rb
|
122
|
-
- test/twitter_account_test.rb
|
123
127
|
has_rdoc:
|
data/lib/growviral/getter.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module GrowViral
|
2
|
-
module Keystore
|
3
|
-
class Getter
|
4
|
-
def self.get(*args)
|
5
|
-
new(*args).get
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_reader :handle, :config
|
9
|
-
def initialize(handle, deps)
|
10
|
-
@handle = handle
|
11
|
-
@config = deps[:config]
|
12
|
-
end
|
13
|
-
|
14
|
-
def get
|
15
|
-
response = Net::HTTP.get_response(uri)
|
16
|
-
TwitterAccount.new JSON.parse(response.body)
|
17
|
-
end
|
18
|
-
|
19
|
-
def uri
|
20
|
-
@uri ||= URI.parse("#{config.host}/twitter_accounts/#{handle}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|