bowser 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/lib/bowser/version.rb +1 -1
- data/opal/bowser/element.rb +5 -1
- data/opal/bowser/geolocation.rb +136 -0
- data/opal/bowser/http.rb +8 -5
- data/opal/bowser/http/form_data.rb +10 -1
- data/opal/bowser/http/request.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58aa512a6c0f6aedea63aeba23ea9079a88bd6df
|
4
|
+
data.tar.gz: fcecad93587669f19b31b294510defd29d066672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde2064268b7c1fb96826119ed2205284dab29d78acdf3728fcd8d0d6ff44789c98c57aa713403197650700645535ff93355a5b390a3d26f7d6c1c09a2104355
|
7
|
+
data.tar.gz: 2cea386c54a5cc5a4296cf53c258dbf21073fab9ab195e408752dd50c3b197faf315a42d28df5bb9bd61103c038fb17e5aac19530af85b3e0ee940bb05a8dfd0
|
data/.travis.yml
CHANGED
@@ -4,4 +4,9 @@ rvm:
|
|
4
4
|
- 2.3.1
|
5
5
|
- jruby-9.0.5.0
|
6
6
|
- jruby-9.1.1.0
|
7
|
-
before_install:
|
7
|
+
before_install:
|
8
|
+
- wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
|
9
|
+
- tar -xjf phantomjs-2.0.0-ubuntu-12.04.tar.bz2
|
10
|
+
- sudo rm -rf /usr/local/phantomjs/bin/phantomjs
|
11
|
+
- sudo mv phantomjs /usr/local/phantomjs/bin/phantomjs
|
12
|
+
- gem install bundler
|
data/lib/bowser/version.rb
CHANGED
data/opal/bowser/element.rb
CHANGED
@@ -106,7 +106,7 @@ module Bowser
|
|
106
106
|
if `property === false`
|
107
107
|
return false
|
108
108
|
else
|
109
|
-
property = `property
|
109
|
+
property = `property == null ? nil : property`
|
110
110
|
end
|
111
111
|
|
112
112
|
# If it's a method, call it. Otherwise, return it.
|
@@ -117,6 +117,10 @@ module Bowser
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
+
def ==(other)
|
121
|
+
`#@native === #{other.to_n}`
|
122
|
+
end
|
123
|
+
|
120
124
|
def to_n
|
121
125
|
@native
|
122
126
|
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'promise'
|
2
|
+
|
3
|
+
module Bowser
|
4
|
+
class Geolocation
|
5
|
+
class Error < StandardError
|
6
|
+
def self.from_native native
|
7
|
+
new(`#{native}.error`, native)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(message, native)
|
11
|
+
super(message)
|
12
|
+
@native = native
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class PositionError < Error
|
16
|
+
def denied?
|
17
|
+
`#@native.code === 1`
|
18
|
+
end
|
19
|
+
|
20
|
+
def unavailable?
|
21
|
+
`#@native.code === 2`
|
22
|
+
end
|
23
|
+
|
24
|
+
def timeout?
|
25
|
+
`#@native.code === 3`
|
26
|
+
end
|
27
|
+
end
|
28
|
+
NotSupported = Class.new(Error)
|
29
|
+
|
30
|
+
attr_reader :latitude, :longitude, :accuracy, :altitude, :altitude_accuracy, :heading, :speed, :timestamp
|
31
|
+
|
32
|
+
@native = `navigator.geolocation`
|
33
|
+
|
34
|
+
def self.supported?
|
35
|
+
`'geolocation' in navigator`
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.locate options={}
|
39
|
+
p = Promise.new
|
40
|
+
|
41
|
+
if supported?
|
42
|
+
%x{
|
43
|
+
#@native.getCurrentPosition(
|
44
|
+
#{proc { |position| `console.log(position)`; p.resolve(from_native(position)) }},
|
45
|
+
#{proc { |error| `console.error(error)`; p.reject(PositionError.from_native(error)) }},
|
46
|
+
#{Options.new(options).to_n}
|
47
|
+
)
|
48
|
+
}
|
49
|
+
else
|
50
|
+
p.reject NotSupported.new('Geolocation is not supported on this device.')
|
51
|
+
end
|
52
|
+
|
53
|
+
p
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.watch(options={})
|
57
|
+
Watch.new(options)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.from_native native
|
61
|
+
coords = `#{native}.coords`
|
62
|
+
new(
|
63
|
+
latitude: `coords.latitude`,
|
64
|
+
longitude: `coords.longitude`,
|
65
|
+
altitude: `coords.altitude`,
|
66
|
+
accuracy: `coords.accuracy`,
|
67
|
+
altitude_accuracy: `coords.altitudeAccuracy`,
|
68
|
+
heading: `coords.heading`,
|
69
|
+
speed: `coords.speed || nil`,
|
70
|
+
timestamp: `#{native}.timestamp`,
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def initialize(latitude:, longitude:, altitude:, accuracy:, altitude_accuracy:, heading:, speed:, timestamp:)
|
75
|
+
@latitude = latitude
|
76
|
+
@longitude = longitude
|
77
|
+
@altitude = altitude
|
78
|
+
@accuracy = accuracy
|
79
|
+
@altitude_accuracy = altitude_accuracy
|
80
|
+
@heading = heading
|
81
|
+
@speed = speed
|
82
|
+
@timestamp = Time.at(timestamp / 1000)
|
83
|
+
end
|
84
|
+
|
85
|
+
class Watch
|
86
|
+
def initialize(options)
|
87
|
+
@options = Options.new(options)
|
88
|
+
@events = Hash.new { |h,k| h[k] = [] }
|
89
|
+
end
|
90
|
+
|
91
|
+
def on event_name, &block
|
92
|
+
@events[event_name] << block
|
93
|
+
end
|
94
|
+
|
95
|
+
def start
|
96
|
+
%x{
|
97
|
+
#@id = navigator.geolocation.watchPosition(
|
98
|
+
#{proc { |position| success Geolocation.from_native(position) } },
|
99
|
+
#{proc { |error| error PositionError.from_native(error) }},
|
100
|
+
#{@options.to_n}
|
101
|
+
)
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def stop
|
106
|
+
`navigator.geolocation.clearWatch(#@id)`
|
107
|
+
end
|
108
|
+
|
109
|
+
def success location
|
110
|
+
@events[:location].each { |callback| callback.call location }
|
111
|
+
end
|
112
|
+
|
113
|
+
def error error
|
114
|
+
@events[:error].each { |callback| callback.call error }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Options
|
119
|
+
def initialize(high_accuracy: nil,
|
120
|
+
max_age: nil,
|
121
|
+
timeout: nil)
|
122
|
+
@high_accuracy = high_accuracy
|
123
|
+
@max_age = max_age && max_age * 1000 # convert to milliseconds
|
124
|
+
@timeout = timeout && timeout * 1000
|
125
|
+
end
|
126
|
+
|
127
|
+
def to_n
|
128
|
+
{
|
129
|
+
enabledHighAccuracy: @high_accuracy,
|
130
|
+
maximumAge: @max_age,
|
131
|
+
timeout: @timeout,
|
132
|
+
}.reject { |k, v| v.nil? }.to_n
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/opal/bowser/http.rb
CHANGED
@@ -8,29 +8,31 @@ module Bowser
|
|
8
8
|
module HTTP
|
9
9
|
module_function
|
10
10
|
|
11
|
-
def fetch(url, method: :get, headers: {}, data: nil)
|
11
|
+
def fetch(url, method: :get, headers: {}, data: nil, &block)
|
12
12
|
promise = Promise.new
|
13
13
|
request = Request.new(method, url)
|
14
14
|
|
15
15
|
connect_events_to_promise request, promise
|
16
16
|
|
17
|
+
block.call(request) if block_given?
|
17
18
|
request.send(data: data, headers: headers)
|
18
19
|
|
19
20
|
promise
|
20
21
|
end
|
21
22
|
|
22
|
-
def upload(url, data, content_type: 'application/json', method: :post)
|
23
|
+
def upload(url, data, content_type: 'application/json', method: :post, &block)
|
23
24
|
promise = Promise.new
|
24
25
|
request = Request.new(method, url)
|
25
26
|
|
26
27
|
connect_events_to_promise request, promise
|
27
28
|
|
29
|
+
block.call(request) if block_given?
|
28
30
|
request.send(data: data, headers: { 'Content-Type' => content_type })
|
29
31
|
|
30
32
|
promise
|
31
33
|
end
|
32
34
|
|
33
|
-
def upload_files(url, files, key: 'files', key_suffix: '[]', method: :post)
|
35
|
+
def upload_files(url, files, key: 'files', key_suffix: '[]', method: :post, &block)
|
34
36
|
promise = Promise.new
|
35
37
|
request = Request.new(method, url)
|
36
38
|
|
@@ -41,13 +43,14 @@ module Bowser
|
|
41
43
|
form.append "#{key}#{key_suffix}", file
|
42
44
|
end
|
43
45
|
|
46
|
+
block.call(request) if block_given?
|
44
47
|
request.send(data: form)
|
45
48
|
|
46
49
|
promise
|
47
50
|
end
|
48
51
|
|
49
|
-
def upload_file(url, file, key: 'file', method: :post)
|
50
|
-
upload_files(url, [file], key: key, key_suffix: nil, method: method)
|
52
|
+
def upload_file(url, file, key: 'file', method: :post, &block)
|
53
|
+
upload_files(url, [file], key: key, key_suffix: nil, method: method, &block)
|
51
54
|
end
|
52
55
|
|
53
56
|
def connect_events_to_promise(request, promise)
|
@@ -1,8 +1,17 @@
|
|
1
1
|
module Bowser
|
2
2
|
module HTTP
|
3
3
|
class FormData
|
4
|
-
def initialize
|
4
|
+
def initialize attributes={}
|
5
5
|
@native = `new FormData()`
|
6
|
+
attributes.each do |key, value|
|
7
|
+
if `!!value.$$class` && value.respond_to?(:each)
|
8
|
+
value.each do |item|
|
9
|
+
append "#{key}[]", item
|
10
|
+
end
|
11
|
+
else
|
12
|
+
append key, value
|
13
|
+
end
|
14
|
+
end
|
6
15
|
end
|
7
16
|
|
8
17
|
def append key, value
|
data/opal/bowser/http/request.rb
CHANGED
@@ -74,6 +74,18 @@ module Bowser
|
|
74
74
|
def done?
|
75
75
|
ready_state >= DONE
|
76
76
|
end
|
77
|
+
|
78
|
+
def upload
|
79
|
+
@upload ||= Upload.new(`#@native.upload`)
|
80
|
+
end
|
81
|
+
|
82
|
+
class Upload
|
83
|
+
include EventTarget
|
84
|
+
|
85
|
+
def initialize(native)
|
86
|
+
@native = native
|
87
|
+
end
|
88
|
+
end
|
77
89
|
end
|
78
90
|
end
|
79
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bowser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- opal/bowser/event.rb
|
100
100
|
- opal/bowser/event_target.rb
|
101
101
|
- opal/bowser/file_list.rb
|
102
|
+
- opal/bowser/geolocation.rb
|
102
103
|
- opal/bowser/http.rb
|
103
104
|
- opal/bowser/http/form_data.rb
|
104
105
|
- opal/bowser/http/request.rb
|