insightexchange 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: 5392c62d19d3e6764918a859ced2d12237d48d1a
4
+ data.tar.gz: 5613ec309b1c5673f4f1883c3cc3480ec0c64218
5
+ SHA512:
6
+ metadata.gz: 13bfaa9b3b12e8ce48a2cf5c739d0f31220d00908820f8b0b2f38e2ebb6dc7dfffdba38c3de6441e8b962516bb466a5c66e7ee893ada122caf863e0f1c45eef4
7
+ data.tar.gz: 84c5612a1f5e49a85fa8159da48a35028262a4bfcef729f3898aff462b6e4c75486a6b8ae183563c37112fa0d13b6156909b9846eae0379b178c100e876bb4a5
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ insightexchange
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in insightexchange.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Liberatus Software, LLC
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,50 @@
1
+ # InsightExchange Ruby Gem
2
+
3
+ This is a simple wrapper gem for the InsightExchange REST API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'insightexchange'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install insightexchange
18
+
19
+ ## Usage
20
+
21
+ Instantiate a new client, providing the API token either through an environment variable or as an argument.
22
+
23
+ ```ruby
24
+ exchange = InsightExchange.new #reads from ENV['INSIGHT_EXCHANGE_TOKEN']
25
+ exchange.publish user.email, 'CookedDinner'
26
+ # This will publish the insight and do one of the following.
27
+ # 1. If it is a new type of insight, it will be submitted for approval
28
+ # first before being sent to anyone else.
29
+ # 2. If we have already approved insights by that title, it will
30
+ # auction the insight off to the highest bidder that you have
31
+ # accepted.
32
+ #
33
+ ```
34
+
35
+ Also, identify users early on in your registration flow to ensure breadth of coverage on the market.
36
+
37
+ ```ruby
38
+ exchange.identify user.email
39
+ ```
40
+
41
+ Please see the InsightExchange documentation for further details.
42
+ http://insightexchange.co/for_developers/docs
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/insightexchange/insightexchange/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'insightexchange/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "insightexchange"
8
+ spec.version = InsightExchange::VERSION
9
+ spec.authors = ["winfred"]
10
+ spec.email = ["winfred@liberat.us"]
11
+ spec.summary = %q{This is a tiny wrapper for the InsightExchange.co REST api.}
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_dependency "httparty"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "~> 2.14.1"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "webmock"
27
+ end
@@ -0,0 +1,3 @@
1
+ class InsightExchange
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,59 @@
1
+ require 'insightexchange/version'
2
+ require 'httparty'
3
+
4
+ class InsightExchange
5
+ include ::HTTParty
6
+ base_uri 'https://secure.insightexchange.co/sellers/api'
7
+ format :json
8
+
9
+ class MissingTokenError < RuntimeError; end
10
+
11
+ attr_accessor :api_token
12
+
13
+ def initialize(api_token = ENV['INSIGHT_EXCHANGE_TOKEN'])
14
+ self.api_token = api_token
15
+ end
16
+
17
+ def publish(email_address, insight_name, data = {})
18
+ ensure_api_token!
19
+ ensure_insight_name!(insight_name)
20
+ ensure_email_address!(email_address)
21
+
22
+ self.class.post("/insights.json", body: {
23
+ api_token: api_token,
24
+ insight: {
25
+ email: email_address,
26
+ name: insight_name,
27
+ data: data
28
+ }
29
+ })
30
+ end
31
+
32
+ def identify(email_address)
33
+ ensure_api_token!
34
+ ensure_email_address!(email_address)
35
+
36
+ self.class.post("/users.json", body: {
37
+ api_token: api_token,
38
+ user: {
39
+ email: email_address
40
+ }
41
+ })
42
+ end
43
+
44
+ private
45
+
46
+ def ensure_api_token!
47
+ if api_token.nil? || api_token.length == 0
48
+ raise MissingTokenError.new('No API token was provided for InsightExchange, either through an ENV variable or the client initializer.')
49
+ end
50
+ end
51
+
52
+ def ensure_email_address!(email_address)
53
+ raise ArgumentError.new('missing email address') unless email_address && email_address.length > 1
54
+ end
55
+
56
+ def ensure_insight_name!(insight_name)
57
+ raise ArgumentError.new('missing insight name') unless insight_name && insight_name.length > 1
58
+ end
59
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe InsightExchange do
4
+ let(:api_token) { 'abc123' }
5
+ let(:exchange) { InsightExchange.new(api_token) }
6
+
7
+ describe 'reading options from ENV variables' do
8
+ before { ENV['INSIGHT_EXCHANGE_TOKEN'] = api_token }
9
+ after { ENV['INSIGHT_EXCHANGE_TOKEN'] = nil }
10
+
11
+ it 'reads INSIGHT_EXCHANGE_TOKEN' do
12
+ client = InsightExchange.new
13
+ expect(client.api_token).to eql(api_token)
14
+ end
15
+ end
16
+
17
+ describe '#publish' do
18
+ let(:request_body) { 'api_token=abc123&insight[email]=this_email%40that_address.com&insight[name]=CreatedPopularPoem' }
19
+
20
+ describe 'when valid inputs' do
21
+ it 'POSTS to InsightExchange api' do
22
+ stub_request(:post, 'https://secure.insightexchange.co/sellers/api/insights.json').
23
+ with(:body => request_body).
24
+ to_return(:status => 200, :body => "", :headers => {})
25
+
26
+ exchange.publish 'this_email@that_address.com', 'CreatedPopularPoem'
27
+
28
+ assert_requested(:post, 'https://secure.insightexchange.co/sellers/api/insights.json') do
29
+ request_body
30
+ end
31
+ end
32
+
33
+ it 'POSTS arbitrary data' do
34
+ request_body = 'api_token=abc123&insight[email]=this_email%40that_address.com&insight[name]=CreatedPopularPoem&insight[data][arbitrary]=data'
35
+
36
+ stub_request(:post, 'https://secure.insightexchange.co/sellers/api/insights.json').
37
+ with(:body => request_body).
38
+ to_return(:status => 200, :body => "", :headers => {})
39
+
40
+ exchange.publish 'this_email@that_address.com', 'CreatedPopularPoem', arbitrary: 'data'
41
+
42
+ assert_requested(:post, 'https://secure.insightexchange.co/sellers/api/insights.json') do
43
+ request_body
44
+ end
45
+ end
46
+ end
47
+
48
+ describe 'when invalid inputs' do
49
+
50
+ it 'raises when missing api_token' do
51
+ expect {
52
+ InsightExchange.new.publish 'this_email@that_address.com', 'CreatedPopularPoem'
53
+ }.to raise_error(InsightExchange::MissingTokenError)
54
+ end
55
+
56
+ it 'raises when missing email_address' do
57
+ expect {
58
+ exchange.publish '', 'SomeInsight'
59
+ }.to raise_error(ArgumentError)
60
+ end
61
+
62
+ it 'raises when missing insight_name' do
63
+ expect {
64
+ exchange.publish 'this_email@that_address.com', ''
65
+ }.to raise_error(ArgumentError)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '#identify' do
71
+
72
+ describe 'when valid inputs' do
73
+ let(:request_body) { 'api_token=abc123&user[email]=this_email%40that_address.com' }
74
+
75
+ it 'POSTS to InsightExchange api' do
76
+ stub_request(:post, 'https://secure.insightexchange.co/sellers/api/users.json').
77
+ with(:body => request_body).
78
+ to_return(:status => 200, :body => "", :headers => {})
79
+
80
+ exchange.identify 'this_email@that_address.com'
81
+
82
+ assert_requested(:post, 'https://secure.insightexchange.co/sellers/api/users.json') do
83
+ request_body
84
+ end
85
+ end
86
+ end
87
+
88
+ describe 'when invalid inputs' do
89
+
90
+ it 'raises when missing api_token' do
91
+ expect {
92
+ InsightExchange.new.identify 'this_email@that_address.com'
93
+ }.to raise_error(InsightExchange::MissingTokenError)
94
+ end
95
+
96
+ it 'raises when missing email_address' do
97
+ expect {
98
+ exchange.identify ''
99
+ }.to raise_error(ArgumentError)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'pry'
4
+ require 'webmock/rspec'
5
+
6
+ require 'insightexchange'
7
+
8
+
9
+ RSpec.configure do |config|
10
+ # some (optional) config here
11
+
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+
14
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: insightexchange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - winfred
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
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
+ description:
98
+ email:
99
+ - winfred@liberat.us
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".ruby-gemset"
106
+ - ".ruby-version"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - insightexchange.gemspec
112
+ - lib/insightexchange.rb
113
+ - lib/insightexchange/version.rb
114
+ - spec/insightexchange_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: This is a tiny wrapper for the InsightExchange.co REST api.
140
+ test_files:
141
+ - spec/insightexchange_spec.rb
142
+ - spec/spec_helper.rb