sigimera 0.0.1 → 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.
- data/.gitignore +2 -0
- data/.rspec +3 -0
- data/Gemfile.lock +9 -3
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/bin/sigimera +90 -0
- data/lib/sigimera.rb +3 -1
- data/lib/sigimera/client.rb +11 -3
- data/lib/sigimera/data/crisis.rb +30 -0
- data/lib/sigimera/version.rb +2 -2
- data/sigimera.gemspec +2 -0
- data/spec/api/client_crises_spec.rb +2 -2
- data/spec/api/client_static_spec.rb +2 -1
- data/spec/data/crisis_spec.rb +66 -0
- metadata +26 -5
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sigimera (0.0
|
4
|
+
sigimera (0.1.0)
|
5
5
|
json
|
6
6
|
nokogiri
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
+
builder (3.1.4)
|
11
12
|
diff-lcs (1.1.3)
|
12
13
|
json (1.7.5)
|
13
|
-
multi_json (1.
|
14
|
+
multi_json (1.4.0)
|
14
15
|
nokogiri (1.5.5)
|
15
16
|
rake (10.0.2)
|
16
17
|
rspec (2.12.0)
|
17
18
|
rspec-core (~> 2.12.0)
|
18
19
|
rspec-expectations (~> 2.12.0)
|
19
20
|
rspec-mocks (~> 2.12.0)
|
20
|
-
rspec-core (2.12.
|
21
|
+
rspec-core (2.12.1)
|
21
22
|
rspec-expectations (2.12.0)
|
22
23
|
diff-lcs (~> 1.1.3)
|
23
24
|
rspec-mocks (2.12.0)
|
25
|
+
rspec_junit_formatter (0.1.4)
|
26
|
+
builder
|
27
|
+
rspec (~> 2.0)
|
28
|
+
rspec-core (!= 2.12.0)
|
24
29
|
simplecov (0.7.1)
|
25
30
|
multi_json (~> 1.0)
|
26
31
|
simplecov-html (~> 0.7.1)
|
@@ -33,6 +38,7 @@ PLATFORMS
|
|
33
38
|
DEPENDENCIES
|
34
39
|
rake
|
35
40
|
rspec
|
41
|
+
rspec_junit_formatter
|
36
42
|
sigimera!
|
37
43
|
simplecov
|
38
44
|
spork
|
data/README.md
CHANGED
@@ -3,6 +3,8 @@ Sigimera Client
|
|
3
3
|
|
4
4
|
[](https://travis-ci.org/Sigimera/sigimera-ruby-client) [](https://codeclimate.com/github/Sigimera/sigimera-ruby-client)
|
6
|
+
[](https://gemnasium.com/Sigimera/sigimera-ruby-client)
|
6
8
|
|
7
9
|
The following ruby gem encapsulates access to the Sigimera REST API under
|
8
10
|
http://api.sigimera.org. It includes the needed SSL certificate for the
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ Bundler::GemHelper.install_tasks
|
|
10
10
|
require 'rspec/core/rake_task'
|
11
11
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
12
|
t.fail_on_error = true
|
13
|
-
t.rspec_opts = "--colour --format documentation
|
13
|
+
t.rspec_opts = "--colour --format documentation --format RspecJunitFormatter --out rspec.xml"
|
14
14
|
end
|
15
15
|
|
16
16
|
task :default => :spec
|
data/bin/sigimera
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#####
|
3
|
+
# Copyright (c) 2012 by Sigimera
|
4
|
+
# All rights reserved.
|
5
|
+
# See MIT-LICENSE for permissions.
|
6
|
+
#####
|
7
|
+
require 'rubygems'
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'sigimera'
|
12
|
+
rescue LoadError
|
13
|
+
STDERR.puts "Install the missing library:\n\t \e[0;36m$\e[m \e[0;32mgem install sigimera\e[m"
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
file = File.join(Dir.home, ".sigimera")
|
19
|
+
Dir.mkdir(File.join(Dir.home, ".sigimera"), 0700) unless File.directory? file
|
20
|
+
credentials = JSON.parse(File.read(File.join(file, "credentials.json")))
|
21
|
+
@auth_token = credentials['auth_token']
|
22
|
+
rescue => e
|
23
|
+
STDERR.puts "Please execute:"
|
24
|
+
STDERR.puts "\t$ curl -X POST -u youremail@example.org https://api.sigimera.org/v1/tokens.json > ~/.sigimera/credentials.json"
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def make_api_call(options)
|
30
|
+
if @auth_token
|
31
|
+
@client = Sigimera::Client.new @auth_token
|
32
|
+
yield
|
33
|
+
else
|
34
|
+
STDERR.puts "Please execute:"
|
35
|
+
STDERR.puts "\t$ curl -X POST -u youremail@example.org https://api.sigimera.org/v1/tokens.json > ~/.sigimera/credentials.json"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
options = {}
|
40
|
+
|
41
|
+
opt_parser = OptionParser.new do |opt|
|
42
|
+
opt.banner = "Usage: sigimera COMMAND [OPTIONS] [ID]"
|
43
|
+
opt.separator ""
|
44
|
+
opt.separator "Commands"
|
45
|
+
opt.separator " get_latest_crises: retrieves the latest 10 crises"
|
46
|
+
opt.separator " get_crisis: retrieves a single crisis with [ID]"
|
47
|
+
opt.separator ""
|
48
|
+
opt.separator "Options"
|
49
|
+
|
50
|
+
opt.on("-h","--help","help") do
|
51
|
+
STDOUT.puts opt_parser
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
opt_parser.parse!
|
57
|
+
|
58
|
+
case ARGV[0]
|
59
|
+
when "get_latest_crises"
|
60
|
+
make_api_call(options) do
|
61
|
+
crises = @client.get_latest_crises :output => "short"
|
62
|
+
crises.each do |crisis|
|
63
|
+
STDOUT.puts "--------"
|
64
|
+
STDOUT.puts "ID : #{crisis['_id']}"
|
65
|
+
STDOUT.puts "Title : #{crisis['dc_title']}"
|
66
|
+
STDOUT.puts "Date : #{crisis['dc_date']}"
|
67
|
+
STDOUT.puts ""
|
68
|
+
end
|
69
|
+
end
|
70
|
+
when "get_crisis"
|
71
|
+
if ARGV[1]
|
72
|
+
make_api_call(options) do
|
73
|
+
crisis = @client.get_crisis ARGV[1]
|
74
|
+
if crisis
|
75
|
+
STDOUT.puts "============"
|
76
|
+
STDOUT.puts "ID | #{crisis['_id']}"
|
77
|
+
STDOUT.puts "Title | #{crisis['dc_title']}"
|
78
|
+
STDOUT.puts "Date | #{crisis['dc_date']}"
|
79
|
+
STDOUT.puts "Description| #{crisis['dc_description']}"
|
80
|
+
STDOUT.puts ""
|
81
|
+
else
|
82
|
+
STDOUT.puts "No crisis could be found with the ID '#{ARGV[1]}'"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
else
|
86
|
+
STDERR.puts "Please specify the identifier of the crisis."
|
87
|
+
end
|
88
|
+
else
|
89
|
+
STDOUT.puts opt_parser
|
90
|
+
end
|
data/lib/sigimera.rb
CHANGED
@@ -10,10 +10,12 @@ module Sigimera
|
|
10
10
|
# The Sigimera REST API Host
|
11
11
|
API_HOST = "https://api.sigimera.org"
|
12
12
|
|
13
|
-
# The used SSL certificate for the HTTPS
|
13
|
+
# The used SSL certificate for the HTTPS connection
|
14
14
|
CACERT_FILE = File.expand_path("../../certs/cacert.crt", __FILE__)
|
15
15
|
end
|
16
16
|
|
17
17
|
require "sigimera/version"
|
18
18
|
require "sigimera/http_helper"
|
19
19
|
require "sigimera/client"
|
20
|
+
|
21
|
+
require "sigimera/data/crisis"
|
data/lib/sigimera/client.rb
CHANGED
@@ -30,7 +30,7 @@ module Sigimera
|
|
30
30
|
def self.get_public_crises
|
31
31
|
client = Sigimera::Client.new
|
32
32
|
response = client.get("/public/crises.json")
|
33
|
-
JSON.parse
|
33
|
+
Client.json_array_to_crisis_array(JSON.parse(response.body)) if response
|
34
34
|
end
|
35
35
|
|
36
36
|
# This method returns the latest 10 crises as RSS feed,
|
@@ -66,7 +66,7 @@ module Sigimera
|
|
66
66
|
endpoint = "/v1/crises.json?auth_token=#{@auth_token}"
|
67
67
|
endpoint += "&#{URI.encode_www_form params}" if params
|
68
68
|
response = self.get(endpoint.to_s)
|
69
|
-
JSON.parse
|
69
|
+
Client.json_array_to_crisis_array(JSON.parse(response.body)) if response and response.body
|
70
70
|
end
|
71
71
|
|
72
72
|
# This method returns a single crisis.
|
@@ -78,7 +78,7 @@ module Sigimera
|
|
78
78
|
endpoint = "/v1/crises/#{identifier}.json?auth_token=#{@auth_token}"
|
79
79
|
endpoint += "&#{URI.encode_www_form params}" if params
|
80
80
|
response = self.get(endpoint)
|
81
|
-
JSON.parse response.body if response and response.body
|
81
|
+
Sigimera::Crisis.new JSON.parse response.body if response and response.body
|
82
82
|
end
|
83
83
|
|
84
84
|
# This method returns statistic information about the crises.
|
@@ -101,5 +101,13 @@ module Sigimera
|
|
101
101
|
# The authentication token that is used for the API calls.
|
102
102
|
attr_reader :auth_token
|
103
103
|
|
104
|
+
# Converts a JSON array into an array of #{Crisis} objects
|
105
|
+
def self.json_array_to_crisis_array json_array
|
106
|
+
crises_array = Array.new
|
107
|
+
json_array.each do |crisis|
|
108
|
+
crises_array << Sigimera::Crisis.new(crisis)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
104
112
|
end
|
105
113
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# This library encapsulates the Sigimera REST API access. For more information
|
4
|
+
# about the API see http://api.sigimera.org
|
5
|
+
#
|
6
|
+
# Author:: Alex Oberhauser (mailto:alex.oberhauser@sigimera.org)
|
7
|
+
# Copyright:: Copyright (c) 2012 Sigimera
|
8
|
+
# License:: MIT
|
9
|
+
module Sigimera
|
10
|
+
# This class encapsulates the access to crisis JSON objects.
|
11
|
+
# Additional it simulates the access syntax of JSON objects.
|
12
|
+
# For future use this class can implemente different type of checks.
|
13
|
+
class Crisis
|
14
|
+
|
15
|
+
def initialize json_object
|
16
|
+
@crisis = json_object
|
17
|
+
end
|
18
|
+
|
19
|
+
# Simulates the same access as for JSON objects
|
20
|
+
def [](key)
|
21
|
+
@crisis[key.to_s] if @crisis and @crisis.class.eql?(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provides for each json key an instance method
|
25
|
+
def method_missing(method)
|
26
|
+
@crisis[method.to_s] if @crisis and @crisis.class.eql?(Hash) and @crisis.key?(method.to_s)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/sigimera/version.rb
CHANGED
@@ -7,10 +7,10 @@ module Sigimera
|
|
7
7
|
MAJOR = 0
|
8
8
|
|
9
9
|
# The minor version number indicates that new features were added.
|
10
|
-
MINOR =
|
10
|
+
MINOR = 1
|
11
11
|
|
12
12
|
# The tiny number stands for bug fixes.
|
13
|
-
TINY =
|
13
|
+
TINY = 0
|
14
14
|
|
15
15
|
# The extra string marks the version as beta, alpha, rcX, ...
|
16
16
|
EXTRA = nil
|
data/sigimera.gemspec
CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.description = "This is the official ruby library for the Sigimera REST API. It encapsulates the authentication process in a secure way and simplifies the access to the Crises Information Platform."
|
16
16
|
gem.files = `git ls-files`.split("\n")
|
17
17
|
gem.require_paths = [ "lib" ]
|
18
|
+
gem.executables << "sigimera"
|
18
19
|
|
19
20
|
gem.add_runtime_dependency "json"
|
20
21
|
gem.add_runtime_dependency "nokogiri" # XML Parsing
|
@@ -23,4 +24,5 @@ Gem::Specification.new do |gem|
|
|
23
24
|
gem.add_development_dependency "rspec"
|
24
25
|
gem.add_development_dependency "spork"
|
25
26
|
gem.add_development_dependency "simplecov"
|
27
|
+
gem.add_development_dependency "rspec_junit_formatter"
|
26
28
|
end
|
@@ -96,7 +96,7 @@ describe Sigimera::Client do
|
|
96
96
|
sleep 1 # Respect the courtesy limit and wait for one second
|
97
97
|
id = "a8763f7e2c432ebe897a68706dcf8dd49243774d"
|
98
98
|
crisis = @client.get_crisis(id)
|
99
|
-
crisis.class.should eql(
|
99
|
+
crisis.class.should eql(Sigimera::Crisis)
|
100
100
|
crisis['_id'].should eql(id)
|
101
101
|
crisis['dc_title'].should eql("Green flood alert in Australia")
|
102
102
|
crisis['dc_subject'].class.should eql(Array)
|
@@ -115,7 +115,7 @@ describe Sigimera::Client do
|
|
115
115
|
sleep 1 # Respect the courtesy limit and wait for one second
|
116
116
|
id = "a8763f7e2c432ebe897a68706dcf8dd49243774d"
|
117
117
|
crisis = @client.get_crisis(id, { :output => 'short' })
|
118
|
-
crisis.class.should eql(
|
118
|
+
crisis.class.should eql(Sigimera::Crisis)
|
119
119
|
crisis['_id'].should eql(id)
|
120
120
|
crisis['subject'].class.should eql(String)
|
121
121
|
crisis['subject'].should eql("flood")
|
@@ -10,6 +10,7 @@ describe Sigimera::Client do
|
|
10
10
|
|
11
11
|
it ".get_auth_token(username, password)" do
|
12
12
|
if @username and @password
|
13
|
+
sleep 1 # Respect the courtesy limit and wait for one second
|
13
14
|
auth_token = Sigimera::Client.get_auth_token(username = @username, password = @password)
|
14
15
|
auth_token.class.should eql(String)
|
15
16
|
auth_token.should_not be_empty
|
@@ -41,5 +42,5 @@ describe Sigimera::Client do
|
|
41
42
|
crises.xpath("/rss/channel/link/text()").to_s.should eql("http://www.sigimera.org/")
|
42
43
|
crises.xpath("/rss/channel/item").size.should == 10
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Sigimera::Crisis do
|
5
|
+
|
6
|
+
it "#new crisis_as_json" do
|
7
|
+
json = {
|
8
|
+
"_id" => "1234567890ABCDEFG",
|
9
|
+
"dc_subject" => "cyclone",
|
10
|
+
"test_hash" => {
|
11
|
+
"key1" => "value1",
|
12
|
+
"key2" => "value2"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
crisis = Sigimera::Crisis.new json
|
16
|
+
|
17
|
+
# Access the fields with the help of ruby methods
|
18
|
+
crisis._id.class.should eql(String)
|
19
|
+
crisis._id.should eql("1234567890ABCDEFG")
|
20
|
+
|
21
|
+
crisis.dc_subject.class.should eql(String)
|
22
|
+
crisis.dc_subject.should eql("cyclone")
|
23
|
+
|
24
|
+
test_hash = crisis.test_hash
|
25
|
+
test_hash.class.should eql(Hash)
|
26
|
+
test_hash['key1'].class.should eql(String)
|
27
|
+
test_hash['key1'].should eql("value1")
|
28
|
+
test_hash['key2'].class.should eql(String)
|
29
|
+
test_hash['key2'].should eql("value2")
|
30
|
+
|
31
|
+
crisis.no_method.should eql(nil)
|
32
|
+
|
33
|
+
# Simulate JSON object behavior
|
34
|
+
crisis['_id'].class.should eql(String)
|
35
|
+
crisis['_id'].should eql("1234567890ABCDEFG")
|
36
|
+
|
37
|
+
crisis['dc_subject'].class.should eql(String)
|
38
|
+
crisis['dc_subject'].should eql("cyclone")
|
39
|
+
|
40
|
+
test_hash = crisis['test_hash']
|
41
|
+
test_hash.class.should eql(Hash)
|
42
|
+
test_hash['key1'].class.should eql(String)
|
43
|
+
test_hash['key1'].should eql("value1")
|
44
|
+
test_hash['key2'].class.should eql(String)
|
45
|
+
test_hash['key2'].should eql("value2")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#new nil" do
|
49
|
+
crisis = Sigimera::Crisis.new nil
|
50
|
+
crisis.no_method.should eql(nil)
|
51
|
+
crisis['no_key'].should eql(nil)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "#new 'some string'" do
|
55
|
+
crisis = Sigimera::Crisis.new "some string"
|
56
|
+
crisis.no_method.should eql(nil)
|
57
|
+
crisis['no_key'].should eql(nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "#new 23" do
|
61
|
+
crisis = Sigimera::Crisis.new 23
|
62
|
+
crisis.no_method.should eql(nil)
|
63
|
+
crisis['no_key'].should eql(nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sigimera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -107,31 +107,52 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec_junit_formatter
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: This is the official ruby library for the Sigimera REST API. It encapsulates
|
111
127
|
the authentication process in a secure way and simplifies the access to the Crises
|
112
128
|
Information Platform.
|
113
129
|
email:
|
114
130
|
- alex.oberhauser@sigimera.org
|
115
|
-
executables:
|
131
|
+
executables:
|
132
|
+
- sigimera
|
116
133
|
extensions: []
|
117
134
|
extra_rdoc_files: []
|
118
135
|
files:
|
119
136
|
- .gitignore
|
137
|
+
- .rspec
|
120
138
|
- .rvmrc
|
121
139
|
- Gemfile
|
122
140
|
- Gemfile.lock
|
123
141
|
- MIT-LICENSE
|
124
142
|
- README.md
|
125
143
|
- Rakefile
|
144
|
+
- bin/sigimera
|
126
145
|
- certs/cacert.crt
|
127
146
|
- lib/sigimera.rb
|
128
147
|
- lib/sigimera/client.rb
|
148
|
+
- lib/sigimera/data/crisis.rb
|
129
149
|
- lib/sigimera/http_helper.rb
|
130
150
|
- lib/sigimera/version.rb
|
131
151
|
- sigimera.gemspec
|
132
152
|
- spec/api/client_crises_spec.rb
|
133
153
|
- spec/api/client_static_spec.rb
|
134
154
|
- spec/api/client_stats_spec.rb
|
155
|
+
- spec/data/crisis_spec.rb
|
135
156
|
- spec/spec_helper.rb
|
136
157
|
homepage: https://github.com/Sigimera/sigimera-ruby-client
|
137
158
|
licenses:
|
@@ -148,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
169
|
version: '0'
|
149
170
|
segments:
|
150
171
|
- 0
|
151
|
-
hash:
|
172
|
+
hash: 336144546145436383
|
152
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
174
|
none: false
|
154
175
|
requirements:
|
@@ -157,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
178
|
version: '0'
|
158
179
|
segments:
|
159
180
|
- 0
|
160
|
-
hash:
|
181
|
+
hash: 336144546145436383
|
161
182
|
requirements: []
|
162
183
|
rubyforge_project:
|
163
184
|
rubygems_version: 1.8.24
|