location-one 0.0.2

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,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ .bundle
5
+ .config
6
+ coverage
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in calabash-ios-cucumber.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ location-one (0.0.1)
5
+ geocoder (~> 1.1)
6
+ json
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ geocoder (1.1.2)
12
+ json (1.7.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ location-one!
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ location-one
2
+ ============
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
1
+ require 'location-one/core'
@@ -0,0 +1,72 @@
1
+ require 'geocoder'
2
+ require 'json'
3
+ require 'net/http'
4
+
5
+ module LocationOne
6
+ #SUPPORTED_BACKENDS =
7
+ # {
8
+ # :calabashios => {:path => "/uia"},
9
+ # :calabashandroid => {:path => "/uia"},
10
+ # :frank => {:path => "/tbd"},
11
+ #
12
+ # }
13
+
14
+ class Client
15
+ attr_accessor :http, :backend
16
+
17
+ def initialize(backend,opt_client=nil)
18
+ @backend = backend
19
+ @http = opt_client || Net::HTTP.new(backend[:host], backend[:port])
20
+ end
21
+
22
+ def change_location(options, opt_data={})
23
+
24
+ if (options[:latitude] and not options[:longitude]) or
25
+ (options[:longitude] and not options[:latitude])
26
+ raise "Both latitude and longitude must be specified if either is."
27
+ end
28
+ if (options[:latitude])
29
+ change_location_by_coords(options[:latitude], options[:longitude],opt_data)
30
+ else
31
+ if not options[:place]
32
+ raise "Either :place or :latitude and :longitude must be specified."
33
+ end
34
+ change_location_by_place(options[:place],opt_data)
35
+ end
36
+ end
37
+
38
+ def change_location_by_coords(lat, lon,opt_data={})
39
+ req = Net::HTTP::Post.new(backend[:path])
40
+
41
+ body_data = {:action => :change_location,
42
+ :latitude => lat,
43
+ :longitude => lon}.merge(opt_data)
44
+
45
+ req.body = body_data.to_json
46
+
47
+ res = @http.request(req)
48
+
49
+ begin
50
+ @http.finish if @http.started?
51
+ rescue
52
+
53
+ end
54
+ if res.code !='200'
55
+ raise "Response error code #{res.code}, for #{lat}, #{lon} (#{res.body})."
56
+ end
57
+ res.body
58
+ end
59
+
60
+ def self.location_by_place(place)
61
+ results = Geocoder.search(place)
62
+ raise "Got no results for #{place}" if results.empty?
63
+ results.first
64
+ end
65
+
66
+ def change_location_by_place(place,opt_data={})
67
+ best_result = location_by_place(place)
68
+ change_location_by_coords(best_result.latitude, best_result.longitude,opt_data)
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module LocationOne
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "location-one/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "location-one"
7
+ s.version = LocationOne::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Karl Krukow"]
10
+ s.email = ["karl@lesspainful.com"]
11
+ s.homepage = "http://calaba.sh"
12
+ s.summary = %q{Location Simulation Client for Calabash and Frank}
13
+ s.description = %q{Location Simulation Client for Calabash and Frank backends.}
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency( "geocoder","~>1.1")
19
+ s.add_dependency( "json" )
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: location-one
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Karl Krukow
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: geocoder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Location Simulation Client for Calabash and Frank backends.
47
+ email:
48
+ - karl@lesspainful.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - README.md
57
+ - Rakefile
58
+ - lib/location-one.rb
59
+ - lib/location-one/core.rb
60
+ - lib/location-one/version.rb
61
+ - location-one.gemspec
62
+ homepage: http://calaba.sh
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Location Simulation Client for Calabash and Frank
86
+ test_files: []