growviral-warehouse 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: b661f3c703be4bd397ce9e081f35413024ff1140
4
+ data.tar.gz: 695e307778e6dc29d709e1ee75e21f9ffbf0e8df
5
+ SHA512:
6
+ metadata.gz: 1df758db91b8b1a735b896793aaf2038d5a54d886aa0657145d3185a2c71994bb84ebafa292a21a6f15be451972f75f15a670e5ca3b53b015e4d2b2dfb01b51a
7
+ data.tar.gz: 2e590ce1ed35c7d7e5e4364a356616c8c97484015e605783dc8cda9963151d5f7f3e3bf5aa0ec1757c823ae89ac0f6eb0ed180e4784019c67137e826ad929e2c
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in warehouse.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 Warehouse Gem
2
+
3
+ A simple wrapper for the GrowViral Warehouse.
4
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
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
9
+ task default: [:test]
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'warehouse/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "growviral-warehouse"
8
+ spec.version = GrowViral::Warehouse::VERSION
9
+ spec.authors = ["Jeremy Walker"]
10
+ spec.email = ["jez.walker@gmail.com"]
11
+ spec.summary = %q{A wrapper for the GrowViral warehouse.}
12
+ spec.description = ""
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "mocha"
25
+ end
data/lib/warehouse.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require 'json'
4
+
5
+ require 'warehouse/client'
6
+ require 'warehouse/configuration'
7
+ require 'warehouse/registers_followers'
8
+ require 'warehouse/checks_follow_history'
9
+
10
+ module GrowViral
11
+ module Warehouse
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module GrowViral
2
+ module Warehouse
3
+ class ChecksFollowHistory
4
+ def self.exists?(*args)
5
+ new(*args).exists?
6
+ end
7
+
8
+ attr_reader :handle, :following_handle, :config
9
+ def initialize(handle, following_handle, deps)
10
+ @handle = handle
11
+ @following_handle = following_handle
12
+ @config = deps[:config]
13
+ end
14
+
15
+ def exists?
16
+ response = Net::HTTP.get(uri)
17
+ if response.status == 200
18
+ true
19
+ else
20
+ false
21
+ end
22
+ end
23
+
24
+ def uri
25
+ @uri ||= URI.parse("#{config.host}/follows?handle=#{handle}&following_handle=#{following_handle}")
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,19 @@
1
+ module GrowViral
2
+ module Warehouse
3
+ class Client
4
+
5
+ attr_reader :config
6
+ def initialize(env)
7
+ @config = Configuration.new(env)
8
+ end
9
+
10
+ def register_follow!(handle, following_handle)
11
+ RegistersFollows.register(handle, following_handle, config: config)
12
+ end
13
+
14
+ def has_follow_history?(handle, following_handle)
15
+ ChecksFollowHistory.exists?(handle, following_handle, config: config)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module GrowViral
2
+ module Warehouse
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_WAREHOUSE_HOST"] || "http://localhost:3000"
15
+ when :production
16
+ ENV["GROWVIRAL_WAREHOUSE_HOST"]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module GrowViral
2
+ module Warehouse
3
+ class RegistersFollows
4
+ def self.register(*args)
5
+ new(*args).register
6
+ end
7
+
8
+ attr_reader :handle, :following_handle, :config
9
+ def initialize(handle, following_handle, deps)
10
+ @handle = handle
11
+ @following_handle = following_handle
12
+ @config = deps[:config]
13
+ end
14
+
15
+ def register
16
+ response = Net::HTTP.post_form(uri, form_data)
17
+ JSON.parse(response.body)
18
+ end
19
+
20
+ def uri
21
+ @uri ||= URI.parse("#{config.host}/follows")
22
+ end
23
+
24
+ def form_data
25
+ {
26
+ "handle" => handle,
27
+ "following_handle" => following_handle
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module GrowViral
2
+ module Warehouse
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ChecksFollowHistoryTest < Minitest::Test
4
+ def test_true_for_200
5
+ handle = "foobar"
6
+ following_handle = "barfoo"
7
+
8
+ uri = URI.parse("http://localhost:3000/follows?handle=#{handle}&following_handle=#{following_handle}")
9
+
10
+ Net::HTTP.expects(:get).with(uri).returns(mock(status: 200))
11
+
12
+ client = GrowViral::Warehouse::Client.new(:development)
13
+ actual = client.has_follow_history?(handle, following_handle)
14
+
15
+ assert_equal true, actual
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'test_helper'
2
+
3
+ class RegistersFollowersTest < Minitest::Test
4
+ def test_response_is_correct
5
+ handle = "foobar"
6
+ following_handle = "barfoo"
7
+
8
+ input = {
9
+ "handle" => handle,
10
+ "following_handle" => following_handle,
11
+ }
12
+
13
+ output = {
14
+ "handle" => handle,
15
+ "following_handle" => following_handle,
16
+ }
17
+
18
+ uri = URI.parse("http://localhost:3000/follows")
19
+ Net::HTTP.expects(:post_form).with(uri, input).returns(mock(body: output.to_json))
20
+
21
+ client = GrowViral::Warehouse::Client.new(:development)
22
+ actual = client.register_follow!(handle, following_handle)
23
+
24
+ assert_equal output, actual
25
+ end
26
+ end
27
+
28
+
@@ -0,0 +1,4 @@
1
+ require "minitest/autorun"
2
+ require 'mocha/mini_test'
3
+
4
+ require 'warehouse'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: growviral-warehouse
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-22 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
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - growviral-warehouse.gemspec
82
+ - lib/warehouse.rb
83
+ - lib/warehouse/checks_follow_history.rb
84
+ - lib/warehouse/client.rb
85
+ - lib/warehouse/configuration.rb
86
+ - lib/warehouse/registers_followers.rb
87
+ - lib/warehouse/version.rb
88
+ - test/checks_follow_history_test.rb
89
+ - test/registers_followers_test.rb
90
+ - test/test_helper.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A wrapper for the GrowViral warehouse.
115
+ test_files:
116
+ - test/checks_follow_history_test.rb
117
+ - test/registers_followers_test.rb
118
+ - test/test_helper.rb
119
+ has_rdoc: