groundcrew 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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Citizen Logistics, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ = groundcrew
2
+
3
+ A ruby wrapper for the {Groundcrew API}[http://gcapi.com], with thanks to {rest-client}[http://github.com/adamwiggins/rest-client] and yajl[http://github.com/brianmario/yajl-ruby].
4
+
5
+ == Usage
6
+
7
+ # Invite twitter followers that were recently seen in the bronx to a party?
8
+
9
+ Groundcrew.api(account_id, api_key) do
10
+
11
+ exec '43.222,-104.300',
12
+ "\"Please come to a party downtown!\"\n"+
13
+ "tell participants: bring a small dragon and a game to play with it"
14
+
15
+ end
16
+
17
+
18
+ # Who likes tennis that's currently walking through the bronx?
19
+
20
+ add_person :name => 'jimmy', :phone => '5552508007', :loc => '01060'
21
+
22
+ stream_people :near => '43.222,-104.300' do |person|
23
+ next unless person.bio =~ /tennis/
24
+ puts "#{person.name} is in the area and ready"
25
+ end
26
+
27
+
28
+ # Gather people in teams of six who want to hold signs
29
+
30
+ exec 'London, UK', <<-CEML
31
+ "Sign holding in groups"
32
+ takes 20m
33
+ gather 4-6 signholders with tag sign_holding
34
+ tell signholders:
35
+ greet the other signholders
36
+ make signs and hold them
37
+ CEML
38
+
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2010 Citizen Logistics, Inc. See LICENSE for details.
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "groundcrew"
8
+ gem.summary = %Q{a simple library for running things on http://Groundcrew.us}
9
+ gem.description = %Q{a simple library for running things on http://Groundcrew.us}
10
+ gem.email = "joe@citizenlogistics.com"
11
+ gem.homepage = "http://github.com/citizenlogistics/groundcrew"
12
+ gem.authors = ["Joe Edelman"]
13
+ gem.add_development_dependency "minitest", ">= 0"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ gem.add_dependency('rest-client')
16
+ gem.add_dependency('yajl-ruby')
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ begin
49
+ require 'yard'
50
+ YARD::Rake::YardocTask.new
51
+ rescue LoadError
52
+ task :yardoc do
53
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
54
+ end
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ require 'rest_client'
2
+ require 'yajl/json_gem'
3
+
4
+ class Groundcrew < Struct.new(:squad_id, :api_key)
5
+
6
+ # create a new instance and run a block inside of it to
7
+ # make multiple authenticated calls
8
+ def self.api(squad_id, api_key, &blk)
9
+ new(squad_id, api_key).instance_eval(&blk)
10
+ end
11
+
12
+ # def invite params; post 'people/invite', params; end
13
+
14
+ def exec loc, script, params = {}
15
+ params.merge! :script => script, :loc => loc
16
+ http :post, "/exec", params
17
+ end
18
+
19
+ def add_people folx
20
+ post "/people/import.json", :json => folx.to_json
21
+ end
22
+
23
+ def add_person name, params = {}
24
+ params.merge! :name => name
25
+ add_people [params]
26
+ end
27
+
28
+ def stream_people params = {}
29
+ since = nil
30
+ params[:query] = "s#{squad_id}"
31
+ loop do
32
+ params[:since] = since if since
33
+ http(:get, "stream.js", params).each_line do |line|
34
+ next unless line =~ /^(item|at)\((.*)\);$/
35
+ case $1
36
+ when 'at'; since = $2
37
+ else
38
+ item_args = Yajl::Parser.parse("[#{$2}]")
39
+ next unless item_args[1] =~ /^Person__|^p/
40
+ vals = item_args.pop
41
+ vals.merge! Hash[%w{city_id id name thumb_url lat lng tags latch comm req}.zip(item_args)]
42
+ yield Hashwrapper.new vals
43
+ end
44
+ end
45
+ sleep 10
46
+ end
47
+ end
48
+
49
+
50
+ private # support methods
51
+ def http method, url, params = {}
52
+ params.merge! :api_key => api_key, :squad => squad_id
53
+ params = {:params => params} if method == :get
54
+ RestClient.send(method, "http://gcapi.com/#{url}", params)
55
+ end
56
+
57
+ %w{ get post put delete}.each{ |x| define_method(x){ |*args| perform x, *args; } }
58
+ def perform *args; json_parse http(*args); end
59
+ def json_parse text; Hashwrapper.new(Yajl::Parser.parse(text)); end
60
+
61
+ class Hashwrapper < Struct.new(:hash)
62
+ def method_missing(method_name, *args)
63
+ case child = hash[method_name.to_s]
64
+ when Hash; Hashwrapper.new child
65
+ when Array; child.map{ |x| Hash === x ? Hashwrapper.new(x) : x }
66
+ else child
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'minitest/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'groundcrew'
7
+
8
+ class MiniTest::Unit::TestCase
9
+ end
10
+
11
+ MiniTest::Unit.autorun
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ SQUAD = '4dpsb03a' # replace with yours
4
+ KEY = 'foobar_api_key' # replace with yours
5
+
6
+ YOUR_NAME = 'Some guy' # replace with yours
7
+ YOUR_PHONE = '+19995551212' # replace with yours
8
+
9
+
10
+ class TestGroundcrew < MiniTest::Unit::TestCase
11
+ def test_exec
12
+ Groundcrew.api(SQUAD, KEY) do
13
+ exec 'San Francisco, CA',
14
+ "nab 1 agent within 5mi\n"+
15
+ "tell agent: this is your test message"
16
+ end
17
+ end
18
+
19
+ def test_import
20
+ Groundcrew.api(SQUAD, KEY) do
21
+ add_person YOUR_NAME, :phone => YOUR_PHONE, :loc => 'San Francisco, CA'
22
+ end
23
+ end
24
+
25
+ def test_stream
26
+ Groundcrew.api(SQUAD, KEY) do
27
+ stream_people do |person|
28
+ puts "Someone: #{person.name} at #{person.lat}, #{person.lng}"
29
+ end
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: groundcrew
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Joe Edelman
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-18 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: minitest
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: yard
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: rest-client
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: yajl-ruby
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :runtime
67
+ version_requirements: *id004
68
+ description: a simple library for running things on http://Groundcrew.us
69
+ email: joe@citizenlogistics.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - LICENSE
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - .gitignore
80
+ - LICENSE
81
+ - README.rdoc
82
+ - Rakefile
83
+ - VERSION
84
+ - lib/groundcrew.rb
85
+ - test/helper.rb
86
+ - test/test_groundcrew.rb
87
+ has_rdoc: true
88
+ homepage: http://github.com/citizenlogistics/groundcrew
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --charset=UTF-8
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.6
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: a simple library for running things on http://Groundcrew.us
117
+ test_files:
118
+ - test/helper.rb
119
+ - test/test_groundcrew.rb