Time_Traveler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ config/*
2
+ coverage/*
3
+ spec/fixtures/*
4
+ credentials.yml
5
+ Gemfile.lock
6
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2
5
+ - 2.1
6
+ branches:
7
+ only:
8
+ - master
9
+
10
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'http'
5
+
6
+ gem 'minitest'
7
+ gem 'minitest-rg'
8
+ gem 'rake'
9
+ gem 'vcr'
10
+ gem 'webmock'
11
+ gem 'simplecov'
12
+
13
+ gem 'flog'
14
+ gem 'flay'
15
+ gem 'rubocop'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) Yvonne Shih <yvonshih@gmail.com> Cheng-Han Hsieh <q2221252@gmail.com> Wei Tang Lin <wtlin0711@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Time_Traveler
2
+ Will be a gem to provide trip services.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ require 'rake/testtask'
3
+
4
+ task default: :spec
5
+
6
+ # desc 'Run specs'
7
+ # Rake::TestTask.new(name=:spec) do |t|
8
+ # t.pattern = 'spec/*_spec.rb'
9
+ # end
10
+
11
+ desc 'run tests'
12
+ task :spec do
13
+ sh 'ruby spec/airbnbapi_spec.rb'
14
+ sh 'ruby spec/googledistanceapi_spec.rb'
15
+
16
+ end
17
+
18
+ desc 'delete cassette fixtures'
19
+ task :wipe do
20
+ sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
21
+ puts(ok ? 'Cassettes deleted' : 'No casseettes found')
22
+ end
23
+ end
24
+
25
+ namespace :quality do
26
+ desc 'run all quality checks'
27
+ task all: [:rubocop, :flog, :flay]
28
+
29
+ task :flog do
30
+ sh 'flog lib/'
31
+ end
32
+
33
+ task :flay do
34
+ sh 'flay lib/'
35
+ end
36
+
37
+ task :rubocop do
38
+ sh 'rubocop'
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'Time_Traveler/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'Time_Traveler'
6
+ s.version = Time_Traveler::VERSION
7
+
8
+ s.summary = 'Gets room content from Airbnb'
9
+ s.description = 'Extracts rent informantion from Airbnb'
10
+ s.authors = ['Yvonne Shih', 'Cheng-Han Hsieh', 'Wei Tang Lin']
11
+ s.email = ['yvonshih@gmail.com', 'q2221252@gmail.com', 'wtlin0711@gmail.com']
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- spec/*`.split("\n")
15
+ s.executables << 'Time_Traveler'
16
+
17
+ s.add_runtime_dependency 'http', '~> 2.0'
18
+
19
+ s.add_development_dependency 'minitest', '~> 5.9'
20
+ s.add_development_dependency 'minitest-rg', '~> 5.2'
21
+ s.add_development_dependency 'rake', '~> 11.3'
22
+ s.add_development_dependency 'vcr', '~> 3.0'
23
+ s.add_development_dependency 'webmock', '~> 2.1'
24
+ s.add_development_dependency 'simplecov', '~> 0.12'
25
+ s.add_development_dependency 'flog', '~> 4.4'
26
+ s.add_development_dependency 'flay', '~> 2.8'
27
+ s.add_development_dependency 'rubocop' '~> 0.42'
28
+
29
+ s.homepage = 'https://github.com/Mew-Traveler/Time_Traveler'
30
+ s.license = 'MIT'
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
+ end
data/bin/rent ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
3
+
4
+ require 'Time_Traveler'
5
+
6
+ location = ARGV[0]
7
+ unless location
8
+ puts 'no location'
9
+ exit(1)
10
+ end
11
+
12
+ unless ENV['AIRBNB_API']
13
+ puts 'you haven\'t set your environment variable yet'
14
+ exit(1)
15
+ end
16
+
17
+ airbnb_load = Google::TrafficInfo.find(location: location)
18
+ rooms = airbnb_load.infos
19
+
20
+ puts rooms
data/bin/traffic ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
3
+
4
+ require 'Time_Traveler'
5
+
6
+ origins = ARGV[0]
7
+ destinations = ARGV[1]
8
+ unless origin && destination
9
+ puts 'two arguments are need for origin and destination'
10
+ exit(1)
11
+ end
12
+
13
+ unless ENV['GOOGLE_API']
14
+ puts 'you haven\'t set your environment variable yet'
15
+ exit(1)
16
+ end
17
+
18
+ traffic_load = Airbnb::RentInfo.find(origins: origins, destinations: destinations,mode: )
19
+ distance_data = traffic_load.trafficAnaly
20
+
21
+ puts distance_data
@@ -0,0 +1,2 @@
1
+ files = Dir.glob(File.join(File.dirname(__FILE__), 'Time_Traveler/*.rb'))
2
+ files.each { |lib| require_relative lib }
@@ -0,0 +1,31 @@
1
+ require 'http'
2
+
3
+ module Airbnb
4
+ # Service for all Airbnb API calls
5
+ class AirbnbApi
6
+ #Setting the URL and parameters
7
+ Airbnb_URL = 'https://api.airbnb.com/'
8
+ API_VER = 'v2'
9
+ Airbnb_API_URL = URI.join(Airbnb_URL, "#{API_VER}/")
10
+ Search_URL = URI.join(Airbnb_API_URL, "search_results")
11
+
12
+ def self.config=(credentials)
13
+ @config ? @config.update(credentials) : @config = credentials
14
+ end
15
+
16
+ def self.config
17
+ return @config if @config
18
+ @config = { airbnb_id: ENV['AIRBNB_API'] }
19
+ end
20
+
21
+ def self.rooms_info(location)
22
+ rooms_response = HTTP.get(Search_URL,
23
+ params: { client_id: config[:airbnb_id],
24
+ location: location
25
+ })
26
+ roomsinfo = JSON.load(rooms_response.to_s)['search_results']
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ require 'http'
2
+
3
+ module Google
4
+ # Service for all Google API calls
5
+ class GoogleApi
6
+ #Setting the URL and parameters
7
+ Google_URL = 'https://maps.googleapis.com/maps/api/'
8
+ Search_Type = 'distancematrix'
9
+ Return_Type = 'json'
10
+ Google_API_URL = URI.join(Google_URL, "#{Search_Type}/", "#{Return_Type}")
11
+ #Search_URL = URI.join(Google_API_URL, "#{Parms}")
12
+ attr_reader :google_data
13
+
14
+ def self.config=(credentials)
15
+ @config ? @config.update(credentials) : @config = credentials
16
+ end
17
+
18
+ def self.config
19
+ return @config if @config
20
+ @config = { googlemap_id: ENV['GOOGLE_API'] }
21
+ end
22
+
23
+ def self.analysis(posting_id)
24
+ fb_resource(posting_id)
25
+ end
26
+
27
+ def self.distanceInfo(origins, dest, mode)
28
+ return @distance if @distance
29
+ distanceDetail = HTTP.get(Google_API_URL,
30
+ params:
31
+ {
32
+ key: config['googlemap_id'],
33
+ origins: origins,
34
+ destinations: dest,
35
+ mode: mode
36
+ })
37
+ distance_data = JSON.load(distanceDetail.to_s)['rows'][0]['elements']
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'airbnb_api'
2
+
3
+ module Airbnb
4
+ class RentInfo
5
+ attr_reader :location
6
+ attr_reader :infos
7
+
8
+ def initialize(rooms,info)
9
+ @infos = rooms.map { |item|
10
+ rooms = room(item)
11
+ }
12
+ searchVal(info)
13
+ end
14
+
15
+ def infos
16
+ @infos
17
+ end
18
+
19
+ def self.find(location:)
20
+ @search_info = {api:ENV['AIRBNB_API'],locate:location}
21
+ rooms_data = AirbnbApi.rooms_info(location)
22
+ new(rooms_data,@search_info)
23
+ end
24
+
25
+ private
26
+ def room(item)
27
+ #item = item['listing']
28
+ room = {
29
+ city: item['listing']['city'],
30
+ name: item['listing']['name'],
31
+ pic_url: item['listing']['picture_url'],
32
+ id: item['listing']['id']
33
+ }
34
+ end
35
+
36
+ def searchVal(oriSearch)
37
+ @location = oriSearch['locate']
38
+ @airbnbapi = oriSearch['api']
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'google_api'
2
+
3
+ module Google
4
+ class TrafficInfo
5
+ attr_reader :infos
6
+ attr_reader :origins, :dest, :mode
7
+
8
+
9
+ def initialize(distance,search)
10
+ parseSearch(search)
11
+ @googleapi = ENV['GOOGLE_API']
12
+ @infos = distance.map{ |item|
13
+ infos = info(item)
14
+ }
15
+ end
16
+
17
+ def trafficAnaly
18
+ @infos
19
+ end
20
+
21
+ def self.find(origins:,destinations:,mode:)
22
+ distance_data = GoogleApi.distanceInfo(origins,destinations,mode)
23
+ @search_info = {googleapi:ENV['GOOGLE_API'],originsVal:origins,destVal:destinations,modeVal:mode}
24
+ new(distance_data,@search_info)
25
+ end
26
+
27
+ private
28
+ def parseSearch(sear)
29
+ @origins = sear['originsVal']
30
+ @dest = sear['destVal']
31
+ @mode = sear['modeVal']
32
+ end
33
+
34
+ def info(item)
35
+ info = item[0]
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Time_Traveler
2
+ VERSION = '0.1.0'
3
+ end
Binary file
@@ -0,0 +1,26 @@
1
+ require_relative 'spec_helper.rb'
2
+
3
+ describe 'Load specifications' do
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = CASSETTES_FOLDER
6
+ c.hook_into :webmock
7
+
8
+ c.filter_sensitive_data('<AIRBNB_ID>') {ENV['AIRBNB_API'] }
9
+ c.filter_sensitive_data('<GOOGLEMAP_ID>') {ENV['GOOGLE_API'] }
10
+ end
11
+
12
+ before do
13
+ VCR.insert_cassette CASSETTE_FILE_AIRBNB, record: :new_episodes
14
+ end
15
+
16
+ after do
17
+ VCR.eject_cassette
18
+ end
19
+
20
+ it 'should be able to get the data from Airbnb' do
21
+ airbnb_load = Airbnb::RentInfo.find(location: 'Hsinchu')
22
+ rooms = airbnb_load.infos
23
+ rooms.length.must_be :>,0
24
+ end
25
+
26
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'spec_helper.rb'
2
+
3
+ describe 'Load specifications' do
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = CASSETTES_FOLDER
6
+ c.hook_into :webmock
7
+
8
+ c.filter_sensitive_data('<AIRBNB_ID>') {ENV['AIRBNB_API'] }
9
+ c.filter_sensitive_data('<GOOGLEMAP_ID>') {ENV['GOOGLE_API'] }
10
+ end
11
+
12
+ before do
13
+ VCR.insert_cassette CASSETTE_FILE_GOOGLE, record: :new_episodes
14
+ end
15
+
16
+ after do
17
+ VCR.eject_cassette
18
+ end
19
+
20
+ it 'should be able to get the data from Google' do
21
+ google_load = Google::TrafficInfo.find(
22
+ origins: "Taipei",
23
+ destinations: "Hsinchu",
24
+ mode: "Train"
25
+ )
26
+
27
+ distance =google_load.trafficAnaly
28
+ distance.length.must_be :>,0
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+
5
+ require 'minitest/autorun'
6
+ require 'minitest/rg'
7
+ require 'yaml'
8
+ require 'vcr'
9
+ require 'webmock'
10
+
11
+ # require './lib/airbnb_api.rb'
12
+ # require './lib/google_api.rb'
13
+ # require './lib/rentinfo.rb'
14
+ # require './lib/trafficinfo.rb'
15
+ require_relative '../lib/Time_Traveler'
16
+
17
+ FIXTURES_FOLDER = 'spec/fixtures'
18
+ CASSETTES_FOLDER = "#{FIXTURES_FOLDER}/cassettes"
19
+ CASSETTE_FILE_GOOGLE = 'google_distances'
20
+ CASSETTE_FILE_AIRBNB = 'airbnb_rooms'
21
+
22
+ if File.file?('config/credentials.yml')
23
+ credentials = YAML.load(File.read('config/credentials.yml'))
24
+ ENV['AIRBNB_API'] = credentials[:airbnb_id]
25
+ ENV['GOOGLE_API'] = credentials[:googlemap_id]
26
+ end
27
+
28
+ RESULT_FILE_AIRBNB = "#{FIXTURES_FOLDER}/airbnb_api_results.yml"
29
+ RESULT_FILE_GOOGLEMAP = "#{FIXTURES_FOLDER}/googlemap_api_results.yml"
30
+ # AIRBNB_RESULT = YAML.load(File.read(RESULT_FILE_AIRBNB))
31
+ # GOOGLEMAP_RESULT = YAML.load(File.read(RESULT_FILE_GOOGLEMAP))
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Time_Traveler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yvonne Shih
9
+ - Cheng-Han Hsieh
10
+ - Wei Tang Lin
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-10-30 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: http
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '2.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '2.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: minitest
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '5.9'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.9'
48
+ - !ruby/object:Gem::Dependency
49
+ name: minitest-rg
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '5.2'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '5.2'
64
+ - !ruby/object:Gem::Dependency
65
+ name: rake
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ version: '11.3'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: '11.3'
80
+ - !ruby/object:Gem::Dependency
81
+ name: vcr
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: webmock
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '2.1'
112
+ - !ruby/object:Gem::Dependency
113
+ name: simplecov
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ version: '0.12'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ version: '0.12'
128
+ - !ruby/object:Gem::Dependency
129
+ name: flog
130
+ requirement: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ version: '4.4'
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ~>
142
+ - !ruby/object:Gem::Version
143
+ version: '4.4'
144
+ - !ruby/object:Gem::Dependency
145
+ name: flay
146
+ requirement: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ~>
150
+ - !ruby/object:Gem::Version
151
+ version: '2.8'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '2.8'
160
+ - !ruby/object:Gem::Dependency
161
+ name: rubocop~> 0.42
162
+ requirement: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ description: Extracts rent informantion from Airbnb
177
+ email:
178
+ - yvonshih@gmail.com
179
+ - q2221252@gmail.com
180
+ - wtlin0711@gmail.com
181
+ executables:
182
+ - rent
183
+ - traffic
184
+ extensions: []
185
+ extra_rdoc_files: []
186
+ files:
187
+ - .gitignore
188
+ - .travis.yml
189
+ - Gemfile
190
+ - Gemfile.lock
191
+ - LICENSE
192
+ - README.md
193
+ - Rakefile
194
+ - Time_Traveler.gemspec
195
+ - bin/rent
196
+ - bin/traffic
197
+ - lib/Time_Traveler.rb
198
+ - lib/Time_Traveler/airbnb_api.rb
199
+ - lib/Time_Traveler/google_api.rb
200
+ - lib/Time_Traveler/rentInfo.rb
201
+ - lib/Time_Traveler/trafficinfo.rb
202
+ - lib/Time_Traveler/version.rb
203
+ - spec/.load_spec.rb.swp
204
+ - spec/airbnbapi_spec.rb
205
+ - spec/googledistanceapi_spec.rb
206
+ - spec/spec_helper.rb
207
+ homepage: https://github.com/Mew-Traveler/Time_Traveler
208
+ licenses:
209
+ - MIT
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ! '>='
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ! '>='
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 1.8.23
229
+ signing_key:
230
+ specification_version: 3
231
+ summary: Gets room content from Airbnb
232
+ test_files:
233
+ - spec/airbnbapi_spec.rb
234
+ - spec/googledistanceapi_spec.rb
235
+ - spec/spec_helper.rb