datafiniti 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ require_relative '../../spec_helper'
2
+ # For Ruby < 1.9.3, use this instead of require_relative
3
+ # require (File.expand_path('./../../../spec_helper', __FILE__))
4
+
5
+ describe Datafiniti::Locations do
6
+
7
+ it "must work" do
8
+ "Yay!".must_be_instance_of String
9
+ end
10
+
11
+ describe "default attributes" do
12
+
13
+ it "must include httparty methods" do
14
+ Datafiniti::Locations.must_include HTTParty
15
+ end
16
+
17
+ it "must have the base url set to the Datafiniti API endpoint" do
18
+ Datafiniti::Locations.base_uri.must_equal "https://#{ENV['DATAFINITI_API_KEY']}:@api.datafiniti.co"
19
+ end
20
+
21
+
22
+ end
23
+
24
+ # describe "default instance attributes" do
25
+
26
+ # let(:locations) { Datafiniti::Locations.new(ENV['DATAFINITI_API_KEY']) }
27
+
28
+ # it "must have an id attribute" do
29
+ # location.must_respond_to :token
30
+ # end
31
+
32
+ # it "must have the right id" do
33
+ # location.token.must_equal ENV['DATAFINITI_API_KEY']
34
+ # end
35
+
36
+ # end
37
+
38
+ describe "GET location" do
39
+ let(:locations) { Datafiniti::Locations.new(ENV['DATAFINITI_API_KEY']) }
40
+
41
+ before do
42
+ VCR.insert_cassette 'locations', :record => :new_episodes
43
+ end
44
+
45
+ after do
46
+ VCR.eject_cassette
47
+ end
48
+
49
+ it "records the fixture" do
50
+ Datafiniti::Locations.get('/v2/data/locations/preview?view=location_json&q=city:Austin')
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,100 @@
1
+ require_relative '../../spec_helper'
2
+ # For Ruby < 1.9.3, use this instead of require_relative
3
+ # require (File.expand_path('./../../../spec_helper', __FILE__))
4
+
5
+ describe Datafiniti::User do
6
+
7
+ describe "default attributes" do
8
+
9
+ it "must include httparty methods" do
10
+ Datafiniti::User.must_include HTTParty
11
+ end
12
+
13
+ it "must have the base url set to the Datafiniti API endpoint" do
14
+ Datafiniti::User.base_uri.must_equal "https://#{ENV['DATAFINITI_API_KEY']}:@api.datafiniti.co"
15
+ end
16
+
17
+ end
18
+
19
+ describe "default instance attributes" do
20
+
21
+ let(:user) { Datafiniti::User.new(ENV['DATAFINITI_API_KEY']) }
22
+
23
+ it "must have an id attribute" do
24
+ user.must_respond_to :token
25
+ end
26
+
27
+ it "must have the right id" do
28
+ user.token.must_equal ENV['DATAFINITI_API_KEY']
29
+ end
30
+
31
+ end
32
+
33
+
34
+ describe "GET profile" do
35
+
36
+ let(:user) { Datafiniti::User.new(ENV['DATAFINITI_API_KEY']) }
37
+
38
+ before do
39
+ VCR.insert_cassette 'user', :record => :new_episodes
40
+ end
41
+
42
+ after do
43
+ VCR.eject_cassette
44
+ end
45
+
46
+ # it "records the fixture" do
47
+ # # auth = {username: ENV['DATAFINITI_API_KEY'], password: ''}
48
+ # Datafiniti::User.get("/v2/users/#{ENV['DATAFINITI_API_KEY']}")
49
+ # end
50
+
51
+ it "must have a profile method" do
52
+ user.must_respond_to :profile
53
+ end
54
+
55
+ it "must parse the api response from JSON to Hash" do
56
+ user.profile.must_be_instance_of Hash
57
+ end
58
+
59
+
60
+ describe "dynamic attributes" do
61
+
62
+ before do
63
+ user.profile
64
+ end
65
+
66
+ it "must perform the request and get the data" do
67
+ user.email.must_equal 'test@example.com'
68
+ end
69
+ it "must return the attribute value if present in profile" do
70
+ user.active.must_equal "true"
71
+ user.plan.must_equal JSON.parse('[{"plans": "100000M"}]')
72
+ end
73
+
74
+ it "must raise method missing if attribute is not present" do
75
+ lambda { user.foo_attribute }.must_raise NoMethodError
76
+ end
77
+
78
+ end
79
+
80
+ describe "caching" do
81
+
82
+ # we use Webmock to disable the network connection after
83
+ # fetching the profile
84
+ before do
85
+ user.profile
86
+ stub_request(:any, /api.datafiniti.co/).to_timeout
87
+ end
88
+
89
+ it "must cache the profile" do
90
+ user.profile.must_be_instance_of Hash
91
+ end
92
+
93
+ it "must refresh the profile if forced" do
94
+ lambda { user.profile(true) }.must_raise Timeout::Error
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,25 @@
1
+ #we need the actual library file
2
+ require_relative '../lib/datafiniti'
3
+ # For Ruby < 1.9.3, use this instead of require_relative
4
+ # require(File.expand_path('../../lib/dish', __FILE__))
5
+
6
+ #dependencies
7
+ require 'minitest/autorun'
8
+ require 'webmock/minitest'
9
+ require 'vcr'
10
+ # require 'turn'
11
+
12
+ # Turn.config do |c|
13
+ # # :outline - turn's original case/test outline mode [default]
14
+ # c.format = :outline
15
+ # # turn on invoke/execute tracing, enable full backtrace
16
+ # c.trace = true
17
+ # # use humanized test names (works only with :outline format)
18
+ # c.natural = true
19
+ # end
20
+
21
+ #VCR config
22
+ VCR.configure do |c|
23
+ c.cassette_library_dir = 'spec/fixtures/datafiniti_cassettes'
24
+ c.hook_into :webmock
25
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datafiniti
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.8
5
+ platform: ruby
6
+ authors:
7
+ - Nick Prokesch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webmock
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.18'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: solr_query
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: Allows users to interface with Datafiniti API to retrieve location and
98
+ product records
99
+ email:
100
+ - nick@datafiniti.net
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - datafiniti.gemspec
111
+ - features/empty_results.feature
112
+ - features/escaped_queries.feature
113
+ - features/step_definitions/steps.rb
114
+ - lib/datafiniti.rb
115
+ - lib/datafiniti/api.rb
116
+ - lib/datafiniti/deep_struct.rb
117
+ - lib/datafiniti/error.rb
118
+ - lib/datafiniti/inflector.rb
119
+ - lib/datafiniti/listings.rb
120
+ - lib/datafiniti/locations.rb
121
+ - lib/datafiniti/products.rb
122
+ - lib/datafiniti/users.rb
123
+ - lib/datafiniti/version.rb
124
+ - spec/fixtures/datafiniti_cassettes/user.yml
125
+ - spec/lib/datafiniti/locations_spec.rb
126
+ - spec/lib/datafiniti/users_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: http://www.datafiniti.net
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: A ruby wrapper for the Datafiniti API
152
+ test_files: []