ushahidi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "doodle"
4
+ gem "rest-client"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kang-min Liu
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = ushahidi
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ushahidi
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Kang-min Liu. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ushahidi"
18
+ gem.homepage = "http://github.com/gugod/ushahidi"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ushahidi API}
21
+ gem.description = %Q{The ruby classes that takls to ushahidi platforms. ref: http://wiki.ushahidi.com/doku.php?id=ushahidi_api}
22
+ gem.email = "gugod@gugod.org"
23
+ gem.authors = ["Kang-min Liu"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "ushahidi #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/ushahidi.rb ADDED
@@ -0,0 +1,62 @@
1
+
2
+ require "doodle"
3
+ require "rest-client"
4
+
5
+ class Ushahidi
6
+ class Incident < Doodle
7
+ has :title, :kind => String
8
+ has :description, :kind => String
9
+ has :categories, :init => []
10
+ has :at, :kind => Time
11
+ has :photos, :init => []
12
+ has :news, :init => ""
13
+
14
+ def to_params_hash
15
+ return {
16
+ "incident_title" => title,
17
+ "incident_description" => description,
18
+ "incident_date" => "%02d/%02d/%04d" % [ at.month, at.mday, at.year ],
19
+ "incident_hour" => "%02d" % [ at.hour % 12 ],
20
+ "incident_minute" => "%02d" % [ at.min ],
21
+ "incident_ampm" => at.hour > 12 ? "pm" : "am",
22
+ "incident_category" => categories.join(",")
23
+ }
24
+ end
25
+ end
26
+
27
+ class Report < Doodle
28
+ has :incident, :kind => Incident
29
+ has :location_name, :kind => String
30
+ has :longitude, :kind => Float
31
+ has :latitude, :kind => Float
32
+
33
+ def to_params_hash
34
+ incident.to_params_hash.merge(
35
+ "location_name" => "#{location_name}",
36
+ "longitude" => "#{longitude}",
37
+ "latitude" => "#{latitude}"
38
+ )
39
+ end
40
+ end
41
+
42
+ @@api_base = nil
43
+
44
+ def self.api_base
45
+ @@api_base
46
+ end
47
+
48
+ def self.api_base=(x)
49
+ @@api_base = x
50
+ end
51
+
52
+ def self.post(x)
53
+ raise "No api base" unless @@api_base
54
+ raise "Can only post report" unless x.is_a? Report
55
+
56
+ h = x.to_params_hash
57
+
58
+ h["task"] = "report"
59
+
60
+ RestClient.post(@@api_base, h)
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ushahidi'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,92 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ # API Ref: http://wiki.ushahidi.com/doku.php?id=ushahidi_api
4
+
5
+ describe "Ushahidi" do
6
+ it "can post" do
7
+ Ushahidi.respond_to?(:api_base).should be_true
8
+ Ushahidi.respond_to?(:api_base=).should be_true
9
+ Ushahidi.respond_to?(:post).should be_true
10
+ end
11
+
12
+ if ENV["USHAHIDI_API_BASE"]
13
+ it "can post to #{ENV["USHAHIDI_API_BASE"]}" do
14
+ Ushahidi.api_base = ENV["USHAHIDI_API_BASE"]
15
+
16
+ report = Ushahidi::Report.new(
17
+ :longitude => 180 * [1,-1][rand(2)] * rand,
18
+ :latitude => 90 * [1,-1][rand(2)] * rand,
19
+ :location_name => "Somewhere Center",
20
+ :incident => Ushahidi::Incident.new(
21
+ :title => "Testing ushahidi gem. #{$$} #{rand}",
22
+ :description => "#{$$} #{rand}\nTest Report from Ushahidi Gem.",
23
+ :at => Time.now.utc,
24
+ :categories => [1]
25
+ )
26
+ )
27
+
28
+ response = Ushahidi.post(report)
29
+ response.code.should == 200
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "Ushahidi::Incident" do
35
+ it "has all the required fields" do
36
+ # incident_title - Required. The title of the incident/report.
37
+ # incident_description - Required. The description of the incident/report.
38
+ # incident_date - Required. The date of the incident/report. It usually in the format mm/dd/yyyy.
39
+ # incident_hour - Required. The hour of the incident/report. In the 12 hour format.
40
+ # incident_minute - Required. The minute of the incident/report.
41
+ # incident_ampm - Required. Is the incident/report am or pm. It of the form, am or pm.
42
+ # incident_category - Required. The categories the incident/report belongs to. It should be a comma separated value csv
43
+
44
+ x = Ushahidi::Incident.new(
45
+ :title => "XyZ",
46
+ :description => "Xyz Xyz Xyz",
47
+ :at => Time.utc(2000,5,5,10,5,0),
48
+ :categories => [1,2,3,5]
49
+ )
50
+
51
+ x.to_params_hash.should == {
52
+ "incident_title" => "XyZ",
53
+ "incident_description" => "Xyz Xyz Xyz",
54
+ "incident_date" => "05/05/2000",
55
+ "incident_hour" => "10",
56
+ "incident_minute" => "05",
57
+ "incident_ampm" => "am",
58
+ "incident_category" => "1,2,3,5"
59
+ }
60
+ end
61
+ end
62
+
63
+ describe "Ushahidi::Report" do
64
+ before do
65
+ @report = Ushahidi::Report.new(
66
+ :longitude => 23.45,
67
+ :latitude => 123.45,
68
+ :location_name => "Somewhere Center",
69
+ :incident => Ushahidi::Incident.new(
70
+ :title => "foo",
71
+ :description => "Bar",
72
+ :at => Time.utc(2000, 10, 10, 10, 35, 0),
73
+ :categories => [1,2,3,5]
74
+ )
75
+ )
76
+ end
77
+
78
+ it "has those attribute accessors" do
79
+ @report.to_params_hash.should == {
80
+ "incident_title" => "foo",
81
+ "incident_description" => "Bar",
82
+ "incident_date" => "10/10/2000",
83
+ "incident_hour" => "10",
84
+ "incident_minute" => "35",
85
+ "incident_ampm" => "am",
86
+ "incident_category" => "1,2,3,5",
87
+ "longitude" => "23.45",
88
+ "latitude" => "123.45",
89
+ "location_name" => "Somewhere Center"
90
+ }
91
+ end
92
+ end
data/ushahidi.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ushahidi}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Kang-min Liu}]
12
+ s.date = %q{2011-08-24}
13
+ s.description = %q{The ruby classes that takls to ushahidi platforms. ref: http://wiki.ushahidi.com/doku.php?id=ushahidi_api}
14
+ s.email = %q{gugod@gugod.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/ushahidi.rb",
28
+ "spec/spec_helper.rb",
29
+ "spec/ushahidi_spec.rb",
30
+ "ushahidi.gemspec"
31
+ ]
32
+ s.homepage = %q{http://github.com/gugod/ushahidi}
33
+ s.licenses = [%q{MIT}]
34
+ s.require_paths = [%q{lib}]
35
+ s.rubygems_version = %q{1.8.8}
36
+ s.summary = %q{Ushahidi API}
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<doodle>, [">= 0"])
43
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<doodle>, [">= 0"])
50
+ s.add_dependency(%q<rest-client>, [">= 0"])
51
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<doodle>, [">= 0"])
58
+ s.add_dependency(%q<rest-client>, [">= 0"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ushahidi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Kang-min Liu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-24 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: doodle
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rest-client
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.3.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: jeweler
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.6.2
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: rcov
72
+ requirement: &id006 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *id006
81
+ description: "The ruby classes that takls to ushahidi platforms. ref: http://wiki.ushahidi.com/doku.php?id=ushahidi_api"
82
+ email: gugod@gugod.org
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - .document
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.rdoc
96
+ - Rakefile
97
+ - VERSION
98
+ - lib/ushahidi.rb
99
+ - spec/spec_helper.rb
100
+ - spec/ushahidi_spec.rb
101
+ - ushahidi.gemspec
102
+ homepage: http://github.com/gugod/ushahidi
103
+ licenses:
104
+ - MIT
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: -2787140060294318662
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: "0"
125
+ requirements: []
126
+
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.8
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Ushahidi API
132
+ test_files: []
133
+