geotrigger 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1681ff89f1fb5fa48cee8fb34b31de586e2ca57b
4
- data.tar.gz: c4e1f585cc211d2a40e6ddadf9043ae36a831271
3
+ metadata.gz: 4884037658b1d1060d37d2d134905b6e2b4ee48b
4
+ data.tar.gz: 1f237b42ce60c8ed9ca3df6a5cb6c90540363554
5
5
  SHA512:
6
- metadata.gz: a76125f1e937a2a6dffb38e98a966034adc6dab207743c1dc23b091897ec6f7d606ac1841c678a5922dcd0823c142a704ac0a2a56197d5f34b9ddc3fd29c8d2c
7
- data.tar.gz: cdf2862f6dce564353b9f9f363729a504a75da4f1ae15c6557b1496103d44ac728f040cfe1e304da1eaa9dd1f2b1f845cace0641d3313697f470b8e3d7654f8b
6
+ metadata.gz: a50e202502a0e43566451f2525fda48a8b574537eefe074c2d8503e5493ac75193712f435e9c97ad9cc368e7580ad58720e8969d67b2b0f5b29eb1de4e680e7f
7
+ data.tar.gz: 6080147b5dfcc3f8a73b2ead823a0d0a04dc81316f04b783dc32f78fec39b07d6041696b682d7f682060b69de26be5a88c74fde44253bebe6309777f8aeaca11
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- gem 'httpclient'
4
- gem 'timecop'
2
+ gemspec
@@ -15,4 +15,6 @@ Gem::Specification.new do |gem|
15
15
 
16
16
  gem.add_dependency 'httpclient'
17
17
  gem.add_development_dependency 'timecop'
18
+ gem.add_development_dependency 'rspec'
19
+ gem.add_development_dependency 'pry'
18
20
  end
@@ -19,15 +19,15 @@ module Geotrigger
19
19
  @access_token || @ago.access_token
20
20
  end
21
21
 
22
- def headers
22
+ def headers others = {}
23
23
  {
24
24
  'Content-Type' => 'application/json',
25
25
  'Authorization' => "Bearer #{access_token}"
26
- }
26
+ }.merge others
27
27
  end
28
28
 
29
- def post path, params = {}
30
- r = @hc.post BASE_URL % path, params.to_json, headers
29
+ def post path, params = {}, other_headers = {}
30
+ r = @hc.post BASE_URL % path, params.to_json, headers(other_headers)
31
31
  raise GeotriggerError.new r.body unless r.status == 200
32
32
  h = JSON.parse r.body
33
33
  raise_error h['error'] if h['error']
@@ -3,6 +3,8 @@ module Geotrigger
3
3
  class Trigger < Model
4
4
  include Taggable
5
5
 
6
+ CIRCLE_KEYS = %w[latitude longitude distance]
7
+
6
8
  def self.create session, opts
7
9
  t = Trigger.new session: session
8
10
  t.data = opts
@@ -31,6 +33,11 @@ module Geotrigger
31
33
  post_data['triggerIds'] = post_data.delete 'triggerId'
32
34
  post_data.delete 'tags'
33
35
 
36
+ if circle?
37
+ post_data['condition']['geo'].delete 'geojson'
38
+ post_data['condition']['geo'].delete 'esrijson'
39
+ end
40
+
34
41
  grok_self_from post 'trigger/update', post_data.merge(opts)
35
42
  self
36
43
  end
@@ -40,6 +47,10 @@ module Geotrigger
40
47
  @data = data['triggers'].select {|t| t['triggerId'] == (id || @data['triggerId'])}.first
41
48
  end
42
49
 
50
+ def circle?
51
+ not CIRCLE_KEYS.map {|k| @data['condition']['geo'].keys.include? k}.select {|e| e}.empty?
52
+ end
53
+
43
54
  end
44
55
 
45
56
  end
@@ -1,3 +1,3 @@
1
1
  module Geotrigger
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -3,14 +3,14 @@ require_relative '../helper'
3
3
  describe Geotrigger::Device do
4
4
 
5
5
  let :dev do
6
- s = GT::AGO::Session.new client_id: CONF[:client_id],
6
+ s = Geotrigger::AGO::Session.new client_id: CONF[:client_id],
7
7
  type: :device
8
8
 
9
- # can't use this because GT doesn't know it yet
9
+ # can't use this because Geotrigger doesn't know it yet
10
10
  #
11
11
  ago_did = s.device_data['deviceId']
12
12
 
13
- # make a call to GT so it learns of new device
13
+ # make a call to Geotrigger so it learns of new device
14
14
  #
15
15
  at = s.access_token
16
16
  r = HTTPClient.new.get Geotrigger::Session::BASE_URL % 'device/list',
@@ -23,7 +23,7 @@ describe Geotrigger::Device do
23
23
  #
24
24
  ago_did.should eq gt_did
25
25
 
26
- GT::Device.new client_id: CONF[:client_id],
26
+ Geotrigger::Device.new client_id: CONF[:client_id],
27
27
  client_secret: CONF[:client_secret],
28
28
  device_id: ago_did
29
29
  end
@@ -32,7 +32,7 @@ describe Geotrigger::Device do
32
32
  ts = dev.tags
33
33
  ts.should_not be nil
34
34
  ts.should be_a Array
35
- ts.first.should be_a GT::Tag
35
+ ts.first.should be_a Geotrigger::Tag
36
36
  ts.first.name.should eq dev.default_tag
37
37
  end
38
38
 
@@ -105,4 +105,23 @@ describe Geotrigger::Session do
105
105
  ->{ s.post 'application/permissions' }.should raise_error
106
106
  end
107
107
 
108
+ describe 'post' do
109
+
110
+ let :session do
111
+ s = Geotrigger::Session.new client_id: CONF[:client_id],
112
+ client_secret: CONF[:client_secret]
113
+ end
114
+
115
+ it 'posts to the API' do
116
+ ->{ session.post 'application/permissions' }.should_not raise_error
117
+ end
118
+
119
+ it 'accepts other headers' do
120
+ ->{
121
+ session.post 'application/permissions', {}, {other_header: 'other value'}
122
+ }.should_not raise_error
123
+ end
124
+
125
+ end
126
+
108
127
  end
@@ -19,18 +19,18 @@ describe Geotrigger::Tag do
19
19
  end
20
20
 
21
21
  let :tag do
22
- GT::Tag.create session, tags: "foo#{Time.now.to_i}"
22
+ Geotrigger::Tag.create session, tags: "foo#{Time.now.to_i}"
23
23
  end
24
24
 
25
25
  let :dev do
26
- s = GT::AGO::Session.new client_id: CONF[:client_id],
26
+ s = Geotrigger::AGO::Session.new client_id: CONF[:client_id],
27
27
  type: :device
28
28
 
29
- # can't use this because GT doesn't know it yet
29
+ # can't use this because Geotrigger doesn't know it yet
30
30
  #
31
31
  ago_did = s.device_data['deviceId']
32
32
 
33
- # make a call to GT so it learns of new device
33
+ # make a call to Geotrigger so it learns of new device
34
34
  #
35
35
  at = s.access_token
36
36
  r = HTTPClient.new.get Geotrigger::Session::BASE_URL % 'device/list',
@@ -43,7 +43,7 @@ describe Geotrigger::Tag do
43
43
  #
44
44
  ago_did.should eq gt_did
45
45
 
46
- GT::Device.new client_id: CONF[:client_id],
46
+ Geotrigger::Device.new client_id: CONF[:client_id],
47
47
  client_secret: CONF[:client_secret],
48
48
  device_id: ago_did
49
49
  end
@@ -65,7 +65,7 @@ describe Geotrigger::Tag do
65
65
  end
66
66
 
67
67
  let :trigger do
68
- GT::Trigger.create session, trigger_opts
68
+ Geotrigger::Trigger.create session, trigger_opts
69
69
  end
70
70
 
71
71
  it 'creates a tag' do
@@ -24,12 +24,13 @@ describe Geotrigger::Trigger do
24
24
  end
25
25
 
26
26
  let :trigger do
27
- GT::Trigger.create session, opts
27
+ Geotrigger::Trigger.create session, opts
28
28
  end
29
29
 
30
30
  it 'should create a trigger' do
31
31
  t = trigger
32
32
  t.trigger_id.should_not be nil
33
+ t.condition['geo'].delete 'geojson'
33
34
  t.condition.should eq opts['condition']
34
35
  t.action.should eq opts['action']
35
36
  end
@@ -38,7 +39,7 @@ describe Geotrigger::Trigger do
38
39
  ts = trigger.tags
39
40
  ts.should_not be nil
40
41
  ts.should be_a Array
41
- ts.first.should be_a GT::Tag
42
+ ts.first.should be_a Geotrigger::Tag
42
43
  ts.first.name.should eq trigger.default_tag
43
44
  end
44
45
 
@@ -6,3 +6,4 @@ CONF = YAML.load_file File.expand_path '../config.yml', __FILE__
6
6
 
7
7
  require 'timecop'
8
8
  require 'geotrigger'
9
+ require 'pry'
metadata CHANGED
@@ -1,41 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geotrigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-26 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: timecop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  description: A small ruby client for Esri's Geotrigger service
@@ -45,7 +73,7 @@ executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
- - .gitignore
76
+ - ".gitignore"
49
77
  - Gemfile
50
78
  - README.md
51
79
  - geotrigger.gemspec
@@ -76,17 +104,17 @@ require_paths:
76
104
  - lib
77
105
  required_ruby_version: !ruby/object:Gem::Requirement
78
106
  requirements:
79
- - - '>='
107
+ - - ">="
80
108
  - !ruby/object:Gem::Version
81
109
  version: '0'
82
110
  required_rubygems_version: !ruby/object:Gem::Requirement
83
111
  requirements:
84
- - - '>='
112
+ - - ">="
85
113
  - !ruby/object:Gem::Version
86
114
  version: '0'
87
115
  requirements: []
88
116
  rubyforge_project:
89
- rubygems_version: 2.0.3
117
+ rubygems_version: 2.2.0
90
118
  signing_key:
91
119
  specification_version: 4
92
120
  summary: A small ruby client for Esri's Geotrigger service
@@ -98,3 +126,4 @@ test_files:
98
126
  - spec/geotrigger/tag_spec.rb
99
127
  - spec/geotrigger/trigger_spec.rb
100
128
  - spec/helper.rb
129
+ has_rdoc: