eldoorado 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
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
+
19
+ ## Ignore simplecov results
20
+ /coverage
21
+
22
+ ## Ignore VCR cassettes
23
+ /fixtures
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ rspec --require rspec/pride --format RSpec::Pride
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json'
4
+ gem 'hashie'
5
+ gem 'rest-client'
6
+
7
+ group :test do
8
+ gem 'vcr'
9
+ gem 'rspec-pride'
10
+ gem 'rspec'
11
+ gem 'webmock'
12
+ gem 'simplecov', :require => false
13
+ end
14
+
15
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Geoffrey Schorkopf
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.
@@ -0,0 +1 @@
1
+ Ruby wrapper gem for Eldoorado API
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'eldoorado/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "eldoorado"
7
+ gem.version = Eldoorado::VERSION
8
+ gem.authors = ["Geoff Schorkopf"]
9
+ gem.email = ["gschorkopf@gmail.com"]
10
+ gem.description = %q{Ruby wrapper gem for Eldoorado API}
11
+ gem.summary = %q{Ruby wrapper gem for Eldoorado API}
12
+ gem.homepage = "http://rubygems.org/gems/eldoorado_gem"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'hashie'
4
+ require 'eldoorado/entrant'
5
+ require 'eldoorado/badge_scan'
6
+ require 'eldoorado/company'
7
+ require 'eldoorado/door'
8
+
9
+
10
+ module Eldoorado
11
+ BASE_URL = "http://localhost:3000"
12
+
13
+ class Server
14
+ def self.get_resource(url)
15
+ RestClient.get url
16
+ end
17
+
18
+ def self.post_resource(url, params = {})
19
+ RestClient.post url, params
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ module Eldoorado
2
+ class BadgeScan
3
+ def self.badges_url
4
+ "#{BASE_URL}/badge_scans.json"
5
+ end
6
+
7
+ def self.all
8
+ response = Server.get_resource(badges_url)
9
+ json = JSON.parse response
10
+
11
+ assign_multiple_from_json(json)
12
+ end
13
+
14
+ def self.create(params)
15
+ response = Server.post_resource(badges_url, {badge_scan: params})
16
+ json = JSON.parse response
17
+
18
+ assign_params_from_json(json)
19
+ end
20
+
21
+ def self.assign_multiple_from_json(json)
22
+ json.each_with_object([]) do |data, badge_scans|
23
+ badge_scan = assign_params_from_json(data)
24
+ badge_scans << badge_scan
25
+ end
26
+ end
27
+
28
+ def self.assign_params_from_json(data)
29
+ badge_scan = Hashie::Mash.new
30
+
31
+ badge_scan.entrant_id = data['entrant_id']
32
+ badge_scan.scan_time = data['scan_time']
33
+ badge_scan.door = data['door']
34
+
35
+ badge_scan
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,59 @@
1
+ module Eldoorado
2
+ class Company
3
+ def self.companies_url
4
+ "#{BASE_URL}/companies.json"
5
+ end
6
+
7
+ def self.company_url(id)
8
+ "#{BASE_URL}/companies/#{id}.json"
9
+ end
10
+
11
+ def self.all
12
+ response = Server.get_resource(companies_url)
13
+ json = JSON.parse response
14
+
15
+ assign_multiple_from_json(json)
16
+ end
17
+
18
+ def self.find(id)
19
+ response = Server.get_resource(company_url(id))
20
+ handle_json response
21
+ end
22
+
23
+ def self.find_by_name(name)
24
+ response = Server.get_resource(company_url(name.capitalize))
25
+ handle_json response
26
+ end
27
+
28
+ def self.create(params)
29
+ response = Server.post_resource(companies_url, {company: params})
30
+ handle_json response
31
+ end
32
+
33
+ def self.handle_json(response)
34
+ json = JSON.parse response
35
+ assign_params_from_json(json)
36
+ end
37
+
38
+ def self.assign_multiple_from_json(json)
39
+ json.each_with_object([]) do |data, companies|
40
+ company = assign_params_from_json(data)
41
+ companies << company
42
+ end
43
+ end
44
+
45
+ def self.assign_params_from_json(data)
46
+ company = Hashie::Mash.new
47
+
48
+ company.id = data['id'].to_i
49
+ company.name = data['name']
50
+ company.entrants = Entrant.assign_multiple_from_json(data['entrants'], {badge_scans: :none})
51
+ company.badge_scans = data['entrants'].each_with_object([]) do |entrant, scans|
52
+ scans << BadgeScan.assign_multiple_from_json(entrant['badge_scans'])
53
+ end.flatten
54
+
55
+ company
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,40 @@
1
+ module Eldoorado
2
+ class Door
3
+ def self.doors_url
4
+ "#{BASE_URL}/doors.json"
5
+ end
6
+
7
+ def self.door_url(id)
8
+ "#{BASE_URL}/doors/#{id}.json"
9
+ end
10
+
11
+ def self.find(id)
12
+ response = Server.get_resource(door_url(id))
13
+ handle_json response
14
+ end
15
+
16
+ def self.handle_json(response, options={})
17
+ json = JSON.parse response
18
+ assign_params_from_json(json, options)
19
+ end
20
+
21
+ def self.assign_params_from_json(data, options={})
22
+ door = Hashie::Mash.new
23
+
24
+ door.id = data['id'].to_i
25
+ door.location = data['location']
26
+ door.badge_scans = door_scans(data['location']) unless options[:badge_scans] == :none
27
+
28
+ door
29
+ end
30
+
31
+ def self.door_scans(location)
32
+ @door_scans ||= BadgeScan.all.find_all{|scan| scan.door == location}
33
+ end
34
+
35
+ def self.create(params)
36
+ response = Server.post_resource(doors_url, {door: params})
37
+ handle_json response, badge_scans: :none
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,60 @@
1
+ module Eldoorado
2
+ class Entrant
3
+ def self.entrants_url
4
+ "#{BASE_URL}/entrants.json"
5
+ end
6
+
7
+ def self.entrant_url(id)
8
+ "#{BASE_URL}/entrants/#{id}.json"
9
+ end
10
+
11
+ def self.all
12
+ response = Server.get_resource(entrants_url)
13
+ json = JSON.parse response
14
+
15
+ assign_multiple_from_json(json)
16
+ end
17
+
18
+ def self.find(id)
19
+ response = Server.get_resource(entrant_url(id))
20
+ handle_json response
21
+ end
22
+
23
+ def self.find_by_name(first_name, last_name)
24
+ params = "#{first_name.capitalize},#{last_name.capitalize}"
25
+ response = Server.get_resource(entrant_url(params))
26
+ handle_json response
27
+ end
28
+
29
+ def self.create(params)
30
+ response = Server.post_resource(entrants_url, {entrant: params})
31
+ handle_json response
32
+ end
33
+
34
+ def self.handle_json(response)
35
+ json = JSON.parse response
36
+ assign_params_from_json(json)
37
+ end
38
+
39
+ def self.assign_multiple_from_json(json, options={})
40
+ json.each_with_object([]) do |data, entrants|
41
+ entrant = assign_params_from_json(data, options)
42
+ entrants << entrant
43
+ end
44
+ end
45
+
46
+ def self.assign_params_from_json(data, options={})
47
+ entrant = Hashie::Mash.new
48
+
49
+ entrant.id = data['id'].to_i
50
+ entrant.first_name = data['first_name']
51
+ entrant.last_name = data['last_name']
52
+ entrant.guest = data['guest']
53
+ entrant.access_type = data['access_type']
54
+ entrant.company = data['company']
55
+ entrant.badge_scans = data['badge_scans'] unless options[:badge_scans] == :none
56
+
57
+ entrant
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Eldoorado
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Eldoorado::BadgeScan do
4
+ describe '.all' do
5
+ it "returns all found badge scans" do
6
+ VCR.use_cassette('all_scans') do
7
+ results = described_class.all
8
+ (results.count).should be > 1
9
+ expect(results.first.door).to eq "Atrium Door (In)"
10
+ expect(results.first.entrant_id).to eq 1
11
+ end
12
+ end
13
+ end
14
+
15
+ describe '.create' do
16
+ it "creates a new badge scan" do
17
+ VCR.use_cassette('create_scan') do
18
+ params = {
19
+ entrant_id: Eldoorado::Entrant.find_by_name("Paul", "Finkel").id,
20
+ scan_time: "2013-05-29 04:40:29",
21
+ door_id: 1
22
+ }
23
+ result = described_class.create(params)
24
+ expect(result.door).to eq "Atrium Door (In)"
25
+ expect(result.entrant_id).to eq 1
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Eldoorado::Company do
4
+ describe ".find" do
5
+ it "returns a hash of found company by id" do
6
+ VCR.use_cassette('found_company') do
7
+ result = described_class.find(1)
8
+ expect(result.id).to eq 1
9
+ expect(result.name).to eq "Roximity"
10
+ end
11
+ end
12
+ end
13
+
14
+ describe '.find_by_name' do
15
+ it "returns a hash of found company by name (case insensitive)" do
16
+ VCR.use_cassette('found_company_by_name') do
17
+ result = described_class.find_by_name("roximity")
18
+ expect(result.id).to eq 1
19
+ expect(result.name).to eq "Roximity"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '.all' do
25
+ it "returns all found companies" do
26
+ VCR.use_cassette('all_companies') do
27
+ results = described_class.all
28
+ (results.count).should be > 1
29
+ expect(results.first.name).to eq "Roximity"
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '.create' do
35
+ it "returns the created company" do
36
+ VCR.use_cassette('create_company') do
37
+ params = {name: "Jumpstart Lab"}
38
+ result = described_class.create(params)
39
+ expect(result.name).to eq "Jumpstart Lab"
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '.entrants' do
45
+ it "returns all entrants for the company" do
46
+ VCR.use_cassette('company_entrants') do
47
+ result = described_class.find(1)
48
+ expect(result.entrants.first.first_name).to eq "Paul"
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '.badge_scans' do
54
+ it "returns all badge scans for the company" do
55
+ VCR.use_cassette('company_badge_scans') do
56
+ result = described_class.find(1)
57
+ (result.badge_scans.count).should be > 1
58
+ expect(result.badge_scans.first.door).to eq "Atrium Door (In)"
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Eldoorado::Door do
4
+ describe ".find" do
5
+ it "returns a hash of found door" do
6
+ VCR.use_cassette('found_door') do
7
+ result = described_class.find(1)
8
+ expect(result.id).to eq 1
9
+ expect(result.location).to eq "Atrium Door (In)"
10
+ end
11
+ end
12
+ end
13
+
14
+ describe ".create" do
15
+ it "returns the created entrant" do
16
+ VCR.use_cassette('create_door') do
17
+ params = {location: "Rooftop Escape"}
18
+ result = described_class.create(params)
19
+ expect(result.location).to eq "Rooftop Escape"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".badge_scans" do
25
+ it "returns the badge scans for found door" do
26
+ VCR.use_cassette('badge_scans_door') do
27
+ result = described_class.find(1)
28
+ (result.badge_scans.count).should be > 1
29
+ expect(result.badge_scans.first.door).to eq "Atrium Door (In)"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe Eldoorado::Entrant do
4
+ describe ".find" do
5
+ it "returns a hash of found entrant" do
6
+ VCR.use_cassette('found_entrant') do
7
+ result = described_class.find(1)
8
+ expect(result.id).to eq 1
9
+ expect(result.first_name).to eq "Paul"
10
+ end
11
+ end
12
+ end
13
+
14
+ describe ".find_by_name" do
15
+ it "returns a hash of found entrant, case insensitive" do
16
+ VCR.use_cassette('found_entrant_by_name') do
17
+ result = described_class.find_by_name("paul", "finkel")
18
+ expect(result.id).to eq 1
19
+ expect(result.first_name).to eq "Paul"
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".all" do
25
+ it "returns all found entrants" do
26
+ VCR.use_cassette('all_entrant') do
27
+ results = described_class.all
28
+ (results.count).should be > 1
29
+ expect(results.first.first_name).to eq "Paul"
30
+ end
31
+ end
32
+ end
33
+
34
+ describe ".create" do
35
+ it "returns the created entrant" do
36
+ VCR.use_cassette('create_entrant') do
37
+ params = {first_name: "Geoff",
38
+ last_name: "Schorkopf",
39
+ company_id: 1,
40
+ guest: false}
41
+ result = described_class.create(params)
42
+ expect(result.first_name).to eq "Geoff"
43
+ expect(result.last_name).to eq "Schorkopf"
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ".company" do
49
+ it "returns the company associated with that entrant" do
50
+ VCR.use_cassette('return_entrant_company') do
51
+ result = described_class.find(1)
52
+ expect(result.id).to eq 1
53
+ expect(result.company).to eq "Roximity"
54
+ end
55
+ end
56
+ end
57
+
58
+ describe ".badge_scans" do
59
+ it "returns the badge scans associated with that entrant" do
60
+ VCR.use_cassette('return_entrant_scans') do
61
+ result = described_class.find(1)
62
+ expect(result.id).to eq 1
63
+ (result.badge_scans.count).should be > 1
64
+ expect(result.badge_scans.first.entrant_id).to eq result.id
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'eldoorado'
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
9
+ c.hook_into :webmock
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ config.order = 'random'
18
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eldoorado
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Geoff Schorkopf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Ruby wrapper gem for Eldoorado API
15
+ email:
16
+ - gschorkopf@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - eldoorado.gemspec
29
+ - lib/eldoorado.rb
30
+ - lib/eldoorado/badge_scan.rb
31
+ - lib/eldoorado/company.rb
32
+ - lib/eldoorado/door.rb
33
+ - lib/eldoorado/entrant.rb
34
+ - lib/eldoorado/version.rb
35
+ - spec/eldoorado/badge_scan_spec.rb
36
+ - spec/eldoorado/company_spec.rb
37
+ - spec/eldoorado/door_spec.rb
38
+ - spec/eldoorado/entrant_spec.rb
39
+ - spec/spec_helper.rb
40
+ homepage: http://rubygems.org/gems/eldoorado_gem
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.25
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Ruby wrapper gem for Eldoorado API
64
+ test_files:
65
+ - spec/eldoorado/badge_scan_spec.rb
66
+ - spec/eldoorado/company_spec.rb
67
+ - spec/eldoorado/door_spec.rb
68
+ - spec/eldoorado/entrant_spec.rb
69
+ - spec/spec_helper.rb
70
+ has_rdoc: