growviral-keystore 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ba6dda8ba481d6b95c9d491d72ed75dd0d63247
4
+ data.tar.gz: 39824681c212ae1ff5a9dd3b20713136d9a68b4d
5
+ SHA512:
6
+ metadata.gz: 5ccc4337e36eb0c68c471ad111157d8d275450eddfab34b4f06f8f818f9bf481cce2d3572689603bfa52e6c683c1e66bdcf3bab5a8d6c951179d9d1728a9a4f1
7
+ data.tar.gz: b875ceb1b6ac934019b8ba904f69489fd51eaa186087babecd318ce6cc59fb06396d28301e35ec1914d26e205faeb5b6efcb77d1168b1061108533e30db97bb7
data/.gitignore ADDED
@@ -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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in growviral-keystore.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jeremy Walker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # The GrowViral Keystore Gem
2
+ [![Build Status](https://magnum.travis-ci.com/growviral/keystore_gem.svg?token=5DZ6DA56Z8u55VnUypyT)](https://magnum.travis-ci.com/growviral/keystore_gem)
3
+
4
+ A simple wrapper for the GrowViral Keystore.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = 'test/**/*_test.rb'
8
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'growviral/keystore/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "growviral-keystore"
8
+ spec.version = GrowViral::Keystore::VERSION
9
+ spec.authors = ["Jeremy Walker"]
10
+ spec.email = ["jez.walker@gmail.com"]
11
+ spec.summary = %q{A wrapper for the GrowViral keystore functionality.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest"
23
+ spec.add_development_dependency "mocha"
24
+ end
@@ -0,0 +1,19 @@
1
+ module GrowViral
2
+ module Keystore
3
+ class Client
4
+
5
+ attr_reader :config
6
+ def initialize(env)
7
+ @config = Configuration.new(env)
8
+ end
9
+
10
+ def get(handle)
11
+ Getter.get(handle, config: config)
12
+ end
13
+
14
+ def set(handle, uid, token, secret)
15
+ Setter.set(handle, uid, token, secret, config: config)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ module GrowViral
2
+ module Keystore
3
+ class Configuration
4
+
5
+ attr_reader :env
6
+ def initialize(env)
7
+ @env = env
8
+ end
9
+
10
+ def host
11
+ case env.to_sym
12
+ when :test
13
+ when :development
14
+ ENV["GROWVIRAL_KEYSTORE_HOST"] || "http://localhost:3000"
15
+ when :production
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,15 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require 'json'
4
+
5
+ require "growviral/keystore/version"
6
+ require "growviral/client"
7
+ require "growviral/configuration"
8
+ require "growviral/twitter_account"
9
+ require "growviral/getter"
10
+ require "growviral/setter"
11
+
12
+ module GrowViral
13
+ module Keystore
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module GrowViral
2
+ module Keystore
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module GrowViral
2
+ module Keystore
3
+ class Setter
4
+ def self.set(*args)
5
+ new(*args).set
6
+ end
7
+
8
+ attr_reader :handle, :uid, :token, :secret, :config
9
+ def initialize(handle, uid, token, secret, deps)
10
+ @handle = handle
11
+ @uid = uid
12
+ @token = token
13
+ @secret = secret
14
+ @config = deps[:config]
15
+ end
16
+
17
+ def set
18
+ response = Net::HTTP.post_form(uri, form_data)
19
+ TwitterAccount.new JSON.parse(response.body)
20
+ end
21
+
22
+ def uri
23
+ @uri ||= URI.parse("#{config.host}/twitter_accounts/#{handle}")
24
+ end
25
+
26
+ def form_data
27
+ {
28
+ handle: handle,
29
+ uid: uid,
30
+ token: token,
31
+ secret: secret
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+
@@ -0,0 +1,13 @@
1
+ module GrowViral
2
+ module Keystore
3
+ class TwitterAccount
4
+ attr_reader :uid, :handle, :token, :secret
5
+ def initialize(data)
6
+ @uid = data['uid']
7
+ @handle = data['handle']
8
+ @token = data['token']
9
+ @secret = data['secret']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'test_helper'
2
+
3
+ class GetterTest < Minitest::Test
4
+ def test_response_is_correct
5
+ uid = 1231212
6
+ handle = "foobar"
7
+ token = "asdasda"
8
+ secret = "2349966adasds"
9
+
10
+ data = {
11
+ "handle" => handle,
12
+ "uid" => uid,
13
+ "token" => token,
14
+ "secret" => secret
15
+ }
16
+
17
+ uri = URI.parse("http://localhost:3000/twitter_accounts/#{handle}")
18
+ Net::HTTP.expects(:get_response).with(uri).returns(mock(body: data.to_json))
19
+
20
+ client = GrowViral::Keystore::Client.new(:development)
21
+ account = client.get(handle)
22
+
23
+ assert_equal uid, account.uid
24
+ assert_equal handle, account.handle
25
+ assert_equal token, account.token
26
+ assert_equal secret, account.secret
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'test_helper'
2
+
3
+ class SetterTest < Minitest::Test
4
+ def test_response_is_correct
5
+ uid = 1231212
6
+ handle = "foobar"
7
+ token = "asdasda"
8
+ secret = "2349966adasds"
9
+
10
+ input = {
11
+ handle: handle,
12
+ uid: uid,
13
+ token: token,
14
+ secret: secret
15
+ }
16
+
17
+ output = {
18
+ "handle" => handle,
19
+ "uid" => uid,
20
+ "token" => token,
21
+ "secret" => secret
22
+ }
23
+
24
+ uri = URI.parse("http://localhost:3000/twitter_accounts/#{handle}")
25
+ Net::HTTP.expects(:post_form).with(uri, input).returns(mock(body: output.to_json))
26
+
27
+ client = GrowViral::Keystore::Client.new(:development)
28
+ account = client.set(handle, uid, token, secret)
29
+
30
+ assert_equal uid, account.uid
31
+ assert_equal handle, account.handle
32
+ assert_equal token, account.token
33
+ assert_equal secret, account.secret
34
+ end
35
+ end
36
+
@@ -0,0 +1,4 @@
1
+ require "minitest/autorun"
2
+ require 'mocha/mini_test'
3
+
4
+ require 'growviral/keystore'
@@ -0,0 +1,27 @@
1
+ require_relative 'test_helper'
2
+
3
+ module GrowViral
4
+ module Keystore
5
+ class TwitterAccountTest < Minitest::Test
6
+ def test_initializes_corectly
7
+ uid = 1231212
8
+ handle = "foobar"
9
+ token = "asdasda"
10
+ secret = "2349966adasds"
11
+
12
+ data = {
13
+ "uid" => uid,
14
+ "handle" => handle,
15
+ "token" => token,
16
+ "secret" => secret
17
+ }
18
+
19
+ account = TwitterAccount.new(data)
20
+ assert_equal uid, account.uid
21
+ assert_equal handle, account.handle
22
+ assert_equal token, account.token
23
+ assert_equal secret, account.secret
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: growviral-keystore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Walker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - jez.walker@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - growviral-keystore.gemspec
83
+ - lib/growviral/client.rb
84
+ - lib/growviral/configuration.rb
85
+ - lib/growviral/getter.rb
86
+ - lib/growviral/keystore.rb
87
+ - lib/growviral/keystore/version.rb
88
+ - lib/growviral/setter.rb
89
+ - lib/growviral/twitter_account.rb
90
+ - test/getter_test.rb
91
+ - test/setter_test.rb
92
+ - test/test_helper.rb
93
+ - test/twitter_account_test.rb
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A wrapper for the GrowViral keystore functionality.
118
+ test_files:
119
+ - test/getter_test.rb
120
+ - test/setter_test.rb
121
+ - test/test_helper.rb
122
+ - test/twitter_account_test.rb
123
+ has_rdoc: