g5_foundation_client 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: 105ce37f62316995bc13de1ca695cabc511ae612
4
+ data.tar.gz: c1c8ff75ed1280e15fc1f43a970ef3bbf138d9e7
5
+ SHA512:
6
+ metadata.gz: 97a1355895beb3f2c8b57d3a9b911a7bd24c2e08d692a36888e10ba4cd542633d3ba8bb3c684ba0e5895b846d5ebc08688546bebadb73ff02c1697d0838da31f
7
+ data.tar.gz: 0be6d18fe919210a953ef9146b6c4c6d5f49ed562c6de4dbf6ea9ca82bf5a042ea9e13129265a3a4b2f47ef404fdd0dcad80d6e2fb5b4b192e7e354c47731196
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ # Core
4
+ - 1.9.3
5
+ # Reputation
6
+ - 2.0.0
7
+ # Everybody else
8
+ - 2.1.1
9
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in g5_foundation_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Don Petersen
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,33 @@
1
+ # G5 Foundation Client
2
+
3
+ [![Build Status](https://travis-ci.org/G5/g5_foundation_client.svg)](https://travis-ci.org/G5/g5_foundation_client)
4
+
5
+ A Ruby gem to access G5 services, including [g5-hub](https://github.com/g5/g5-hub).
6
+
7
+ ### Installation
8
+
9
+ Include `g5_foundation_client` in your Gemfile, or manually install with rubygems.
10
+
11
+ ### Usage
12
+
13
+ It's pretty limited right now. You may fetch a Location given a UID, which must point to a G5 Hub Location detail page.
14
+
15
+ ```ruby
16
+ > model = G5FoundationClient::Location.find_by_uid("http://example.com/clients/g5-c-123-test/locations/g5-cl-123-test")
17
+ => #<G5FoundationClient::Location:0x007f4aa8c25ef8
18
+ @name="Location Name",
19
+ @phone="123-123-1234",
20
+ @uid=
21
+ "http://example.com/clients/g5-c-123-test/locations/g5-cl-123-test">
22
+ > model.attributes
23
+ => {:uid=>
24
+ "http://example.com/clients/g5-c-123-test/locations/g5-cl-123-test",
25
+ :name=>"Test Name",
26
+ :phone=>"123-123-1234"}
27
+ ```
28
+
29
+ If this gets much more complicated – and it will – you should probably use YARD and point to rdoc.info, or whatever documentation builder you set up.
30
+
31
+ ### Contributing
32
+
33
+ Create a Github pull request. Please make sure that Travis CI passes before you do.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'g5_foundation_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "g5_foundation_client"
8
+ spec.version = G5FoundationClient::VERSION
9
+ spec.authors = ["Don Petersen"]
10
+ spec.email = ["don@donpetersen.net"]
11
+ spec.summary = %q{Client gem to interact with G5 services.}
12
+ spec.description = %q{Client gem to interact with G5 services.}
13
+ spec.homepage = "https://github.com/g5/g5_foundation_client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "virtus"
22
+ spec.add_dependency "httparty"
23
+ spec.add_dependency "microformats2"
24
+ spec.add_dependency "g5_authentication_client", ">= 0.2"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "webmock"
30
+ spec.add_development_dependency "pry"
31
+ end
@@ -0,0 +1,12 @@
1
+ module G5FoundationClient::Deserializers
2
+ module Location
3
+ def self.from_markup(markup)
4
+ hcard = Microformats2.parse(markup).cards.first
5
+ G5FoundationClient::Location.new(
6
+ uid: hcard.uid.to_s,
7
+ name: hcard.name.to_s,
8
+ phone: hcard.adr.format.tel.to_s
9
+ )
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ class G5FoundationClient::Fetcher
2
+ def self.fetch_url(url, &block)
3
+ response = HTTParty.get(
4
+ url,
5
+ { query: { access_token: G5FoundationClient::access_token } }
6
+ )
7
+
8
+ case response.response.code.to_i
9
+ when 200
10
+ yield response.body
11
+ when 404
12
+ raise G5FoundationClient::RecordNotFoundException.new(
13
+ "Couldn't find record at URL '#{url}'"
14
+ )
15
+ else
16
+ raise Exception.new(
17
+ "I got an unexpected response code '#{response.response.code}'"
18
+ )
19
+ end
20
+ end
21
+
22
+ protected
23
+
24
+ def self.query_options
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ class G5FoundationClient::Location
2
+ include Virtus.model
3
+
4
+ attribute :uid, String
5
+ attribute :name, String
6
+ attribute :phone, String
7
+
8
+ def self.find_by_uid(uid)
9
+ G5FoundationClient::Fetcher.fetch_url(uid) do |markup|
10
+ G5FoundationClient::Deserializers::Location.from_markup(markup)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ class G5FoundationClient::RecordNotFoundException < StandardError
2
+ end
@@ -0,0 +1,3 @@
1
+ module G5FoundationClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require "virtus"
2
+ require "httparty"
3
+ require "microformats2"
4
+ require "g5_authentication_client"
5
+ require "g5_foundation_client/version"
6
+
7
+ module G5FoundationClient
8
+ def self.access_token=(token)
9
+ @access_token = token
10
+ end
11
+
12
+ def self.access_token
13
+ @access_token ||= G5AuthenticationClient::Client.new.get_access_token
14
+ end
15
+
16
+ class RecordNotFoundException < Exception
17
+ end
18
+ end
19
+
20
+ require 'g5_foundation_client/fetcher'
21
+
22
+ require 'g5_foundation_client/models/location'
23
+ require 'g5_foundation_client/deserializers/location'
@@ -0,0 +1,36 @@
1
+
2
+ <!DOCTYPE html>
3
+ <html>
4
+ <head></head>
5
+ <body>
6
+ <section class="h-card">
7
+ <h2>
8
+ <a class="p-name u-uid u-url" href="http://example.com/clients/g5-c-1234-client/locations/g5-cl-1234-location">Test Location</a>
9
+ </h2>
10
+
11
+ <h4>Domain</h4>
12
+ <a class="u-url u-g5-domain" href="http://www.examplelocation.com/">http://www.examplelocation.com/</a>
13
+
14
+ <h4>Address</h4>
15
+ <p class="p-adr h-adr">
16
+ <span class="p-street-address">
17
+ 123 Test Way
18
+ </span>
19
+ <span>
20
+ <span class="p-locality">Testville</span>
21
+ <span class="p-region">GA</span>
22
+ <span class="p-postal-code">12345</span>
23
+ </span>
24
+ <span class="p-tel">123-123-1234</span>
25
+ <span class="p-tel p-fax"></span>
26
+ <span class="u-email"></span>
27
+ </p>
28
+
29
+
30
+ <h4>Client</h4>
31
+ <p class="p-org h-card">
32
+ <a class="p-name u-uid u-url" href="http://example.com/clients/g5-c-1234-client">Test Client</a>
33
+ </p>
34
+ </section>
35
+ </body>
36
+ </html>
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5FoundationClient::Deserializers::Location do
4
+ describe ".from_markup" do
5
+ let(:markup) { fixture("location_detail.html") }
6
+ subject { G5FoundationClient::Deserializers::Location.from_markup(markup) }
7
+
8
+ its(:uid) { should eq("http://example.com/clients/g5-c-1234-client/locations/g5-cl-1234-location") }
9
+ its(:name) { should eq("Test Location") }
10
+ its(:phone) { should eq("123-123-1234") }
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5FoundationClient::Fetcher do
4
+ before { G5FoundationClient.access_token = "token" }
5
+
6
+ describe ".fetch_url" do
7
+ let(:url) { "http://example.com/?access_token=token" }
8
+ subject(:fetch) do
9
+ yielded_markup = nil
10
+ G5FoundationClient::Fetcher.fetch_url(url) do |markup|
11
+ yielded_markup = markup
12
+ end
13
+
14
+ yielded_markup
15
+ end
16
+
17
+ context "when the response is successful" do
18
+ before { stub_json(url, "markup") }
19
+ it { should eq("markup") }
20
+ end
21
+
22
+ context "when there is no Location at that UID" do
23
+ before { stub_json(url, response, 404) }
24
+ let(:response) { %["<html><body>Something went wrong</body></html>] }
25
+
26
+ it "explodes violently" do
27
+ expect { fetch }.to raise_error(
28
+ G5FoundationClient::RecordNotFoundException, /example/
29
+ )
30
+ end
31
+ end
32
+
33
+ context "when there is an unexpected response" do
34
+ before { stub_json(url, response, 418) }
35
+ let(:response) { %[{"error":"I'm a teapot"}] }
36
+
37
+ it "explodes violently" do
38
+ expect { fetch }.to raise_error(/418/)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5FoundationClient::Location do
4
+ before { G5FoundationClient.access_token = "token" }
5
+
6
+ describe "instantiating with a hash" do
7
+ subject do
8
+ G5FoundationClient::Location.new(
9
+ uid: "http://example.com/uid",
10
+ name: "Test Name",
11
+ phone: "123-123-1234"
12
+ )
13
+ end
14
+
15
+ its(:uid) { should eql("http://example.com/uid") }
16
+ its(:name) { should eql("Test Name") }
17
+ its(:phone) { should eql("123-123-1234") }
18
+ end
19
+
20
+ describe ".find_by_uid" do
21
+ let(:uid) do
22
+ "http://example.com/clients/g5-c-1234-client/locations/g5-cl-1234-location"
23
+ end
24
+ let(:response) { fixture("location_detail.html") }
25
+ before { stub_json(uid + "?access_token=token", response) }
26
+ subject(:find) { G5FoundationClient::Location.find_by_uid(uid) }
27
+
28
+ its(:name) { should eq("Test Location") }
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5FoundationClient do
4
+ describe ".access_token" do
5
+ subject { G5FoundationClient.access_token }
6
+
7
+ context "when it has not been set" do
8
+ before do
9
+ G5AuthenticationClient::Client.stub_chain(
10
+ :new,
11
+ get_access_token: "fetched access token"
12
+ )
13
+ end
14
+
15
+ it { should eql("fetched access token") }
16
+ end
17
+
18
+ context "when it has beeen set" do
19
+ before { G5FoundationClient.access_token = "set access token" }
20
+ it { should eql("set access token") }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ require 'g5_foundation_client'
2
+
3
+ require 'pry'
4
+ require 'webmock/rspec'
5
+
6
+ module Webmockery
7
+ def stub_json(url, response, status=200)
8
+ stub_request(
9
+ :get,
10
+ url
11
+ ).to_return(
12
+ body: response,
13
+ status: status,
14
+ headers: {
15
+ content_type: 'application/json'
16
+ }
17
+ )
18
+ end
19
+
20
+ def stub_post(url, response, data, status=200)
21
+ stub_request(
22
+ :post,
23
+ url
24
+ ).with(
25
+ body: data
26
+ ).to_return(
27
+ body: response,
28
+ status: status,
29
+ headers: {
30
+ content_type: 'application/json'
31
+ }
32
+ )
33
+ end
34
+ end
35
+
36
+ module FixturesHelper
37
+ def fixture(fixture_path)
38
+ open(File.join("spec", "fixtures", fixture_path)).read
39
+ end
40
+ end
41
+
42
+ RSpec.configure do |config|
43
+ config.include Webmockery
44
+ config.include FixturesHelper
45
+ config.after { G5FoundationClient.access_token = nil }
46
+ end
data/wooo.creds ADDED
@@ -0,0 +1,6 @@
1
+ ENV["G5_AUTH_CLIENT_ID"] = "88aa19805f81835354be522ff3ff9c44a0c90fbbc3ed4980814a006768333797"
2
+ ENV["G5_AUTH_CLIENT_SECRET"] = "237c83f987a409a2027347bc1ee97c036cc3d9e038fc8db68e7e6ce525955cc5"
3
+ ENV["G5_AUTH_ENDPOINT"] = "https://auth.g5search.com"
4
+ ENV["G5_AUTH_PASSWORD"] = "oaregjoiaergjoierga89489234089imczopuiewrq&@#$%^@UIWECH78623784678328957832NJKHCWUIHCUEKWHEKCHK2u38o2j3aiuwdihla38y29483279482379jcdoajiejc"
5
+ ENV["G5_AUTH_REDIRECT_URI"] = "https://g5-cxm-6d4u4sc-madrona.herokuapp.com/g5_auth/users/auth/g5/callback"
6
+ ENV["G5_AUTH_USERNAME"] = "g5dev+serviceaccount@g5searchmarketing.com"
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: g5_foundation_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Don Petersen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: virtus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: microformats2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: g5_authentication_client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Client gem to interact with G5 services.
140
+ email:
141
+ - don@donpetersen.net
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - g5_foundation_client.gemspec
154
+ - lib/g5_foundation_client.rb
155
+ - lib/g5_foundation_client/deserializers/location.rb
156
+ - lib/g5_foundation_client/fetcher.rb
157
+ - lib/g5_foundation_client/models/location.rb
158
+ - lib/g5_foundation_client/record_not_found_exception.rb
159
+ - lib/g5_foundation_client/version.rb
160
+ - spec/fixtures/location_detail.html
161
+ - spec/lib/g5_foundation_client/deserializers/location_spec.rb
162
+ - spec/lib/g5_foundation_client/fetcher_spec.rb
163
+ - spec/lib/g5_foundation_client/models/location_spec.rb
164
+ - spec/lib/g5_foundation_client_spec.rb
165
+ - spec/spec_helper.rb
166
+ - wooo.creds
167
+ homepage: https://github.com/g5/g5_foundation_client
168
+ licenses:
169
+ - MIT
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.2.0
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Client gem to interact with G5 services.
191
+ test_files:
192
+ - spec/fixtures/location_detail.html
193
+ - spec/lib/g5_foundation_client/deserializers/location_spec.rb
194
+ - spec/lib/g5_foundation_client/fetcher_spec.rb
195
+ - spec/lib/g5_foundation_client/models/location_spec.rb
196
+ - spec/lib/g5_foundation_client_spec.rb
197
+ - spec/spec_helper.rb