sigimera 0.0.1.rc2 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sigimera (0.0.1.rc2)
4
+ sigimera (0.0.1)
5
5
  json
6
6
  nokogiri
7
7
 
data/README.md CHANGED
@@ -1,25 +1,38 @@
1
1
  Sigimera Client
2
2
  ===============
3
3
 
4
- This repository includes a ruby client library for the REST API under http://api.sigimera.org.
4
+ [![Build
5
+ Status](https://secure.travis-ci.org/Sigimera/sigimera-ruby-client.png?branch=master)](https://travis-ci.org/Sigimera/sigimera-ruby-client) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Sigimera/sigimera-ruby-client)
6
+
7
+ The following ruby gem encapsulates access to the Sigimera REST API under
8
+ http://api.sigimera.org. It includes the needed SSL certificate for the
9
+ HTTPS connections and a detailed documentation. This library will be
10
+ developed in parallel to the API.
5
11
 
6
12
 
7
13
  Installation
8
14
  ------------
9
15
 
10
- Install _sigimera_ manually from command line:
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'sigimera'
20
+ ```
21
+
22
+ And then execute:
11
23
 
12
24
  ```sh
13
- gem install sigimera
25
+ $ bundle
14
26
  ```
15
27
 
16
- Add _sigimera_ to your Gemfile:
28
+ Or install it yourself as:
17
29
 
18
- ```ruby
19
- gem 'sigimera'
30
+ ```sh
31
+ $ gem install sigimera
20
32
  ```
21
33
 
22
34
 
35
+
23
36
  Usage
24
37
  -----
25
38
 
@@ -33,11 +46,16 @@ irb
33
46
  >> puts Sigimera::Client.get_api_version
34
47
  >> puts Sigimera::Client.get_public_crises
35
48
  >> puts Sigimera::Client.get_public_rss_feed
49
+ >> puts Sigimera::Client.get_auth_token("johndoe@example.org", "verySecretPassword")
36
50
 
37
51
  # see http://api.sigimera.org/dashboard
38
52
  >> client = Sigimera::Client.new("YourSecretToken")
53
+ or
54
+ # The username and password are NOT stored, but only used to fetch an
55
+ # authentication token
56
+ >> client = Sigimera::Client.new(username = "johndoe@example.org", password = "verySecretPassword")
39
57
  >> puts client.get_latest_crises
40
- >> puts client.get_latest_crises(type = "earthquakes")
58
+ >> puts client.get_latest_crises({ :type => "earthquakes" })
41
59
  >> puts client.get_crises_stat
42
60
  >> puts client.get_user_stat
43
61
  ```
@@ -54,6 +72,7 @@ export AUTH_TOKEN=YourSecretToken
54
72
  rake spec
55
73
  ```
56
74
 
75
+
57
76
  API Documentation
58
77
  -----------------
59
78
 
@@ -1,16 +1,16 @@
1
+ # encoding: UTF-8
1
2
  require "json"
2
3
  require "nokogiri"
4
+ require "base64"
3
5
 
4
6
  module Sigimera
5
7
  # The main class that could be used to access the REST API
6
8
  class Client
7
9
  include Sigimera::HttpHelper
8
10
 
9
- # The authentication token that is used for the API calls.
10
- attr_reader :auth_token
11
-
12
- def initialize(auth_token = nil)
13
- @auth_token = auth_token
11
+ def initialize(auth_token = nil, username = nil, password = nil)
12
+ @auth_token = auth_token if auth_token
13
+ @auth_token = self.get_auth_token(username, password) if username and password
14
14
  end
15
15
 
16
16
  # This method returns current API version. For this purpose
@@ -43,31 +43,63 @@ module Sigimera
43
43
  Nokogiri::XML(response.body) if response
44
44
  end
45
45
 
46
+
47
+ # This method returns an authentication token. If the auth_token
48
+ # exists it is returned, otherwise a new one is created.
49
+ #
50
+ # @param [String] username The username (email) that is used for the basic authentication
51
+ # @param [String] password The password that is used for the basic authentication
52
+ # @return [String] The authentication token as string
53
+ def self.get_auth_token(username, password)
54
+ basic_hash = Base64.strict_encode64("#{username}:#{password}")
55
+ client = Sigimera::Client.new
56
+ response = client.post("/v1/tokens.json", basic_hash)
57
+ json = JSON.parse response.body if response
58
+ json['auth_token'].to_s if json and json['auth_token']
59
+ end
60
+
46
61
  # This method returns the latest 10 crises.
47
62
  #
48
- # @param [String] type The crises type, e.g. earthquake, flood, cyclone, volcanoe
63
+ # @param [String] params A hash that contains the http parameters for the call, e.g. { :type => "earthquake", :level => "red", :output => "short" }
49
64
  # @return [Array] Returns an array of crises objects in JSON
50
- def get_latest_crises(type = nil)
65
+ def get_latest_crises(params = nil)
51
66
  endpoint = "/v1/crises.json?auth_token=#{@auth_token}"
52
- endpoint += "&type=#{type}" if type
67
+ endpoint += "&#{URI.encode_www_form params}" if params
68
+ response = self.get(endpoint.to_s)
69
+ JSON.parse response.body if response and response.body
70
+ end
71
+
72
+ # This method returns a single crisis.
73
+ #
74
+ # @param [String] identifier A unique crisis identifier
75
+ # @return [Hash] The single crisis as JSON object
76
+ def get_crisis(identifier, params = nil)
77
+ return nil if identifier.nil? or identifier.empty?
78
+ endpoint = "/v1/crises/#{identifier}.json?auth_token=#{@auth_token}"
79
+ endpoint += "&#{URI.encode_www_form params}" if params
53
80
  response = self.get(endpoint)
54
- JSON.parse response.body if response
81
+ JSON.parse response.body if response and response.body
55
82
  end
56
83
 
57
84
  # This method returns statistic information about the crises.
58
- #
85
+ #
59
86
  # @return [Array] Returns the crises statistic as JSON object
60
87
  def get_crises_stat
61
88
  response = self.get("/v1/stats/crises.json?auth_token=#{@auth_token}")
62
- JSON.parse response.body if response
89
+ JSON.parse response.body if response and response.body
63
90
  end
64
91
 
65
92
  # This method returns statistic information about user.
66
- #
93
+ #
67
94
  # @return [Array] Returns the user statistic as JSON object
68
95
  def get_user_stat
69
96
  response = self.get("/v1/stats/users.json?auth_token=#{@auth_token}")
70
- JSON.parse response.body if response
97
+ JSON.parse response.body if response and response.body
71
98
  end
99
+
100
+ private
101
+ # The authentication token that is used for the API calls.
102
+ attr_reader :auth_token
103
+
72
104
  end
73
105
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require "net/http"
2
3
 
3
4
  module Sigimera
@@ -18,6 +19,22 @@ module Sigimera
18
19
  http.request(req)
19
20
  end
20
21
 
22
+ # POST endpoint
23
+ #
24
+ # @param [String] endpoint The endpoint that should be called.
25
+ # @param [String] basic_hash Base64.strict_encode64("username:password")
26
+ # @return [Net::HTTPResponse] The HTTP response object
27
+ def post(endpoint, basic_hash = nil)
28
+ uri, http = get_connection(endpoint)
29
+
30
+ req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}")
31
+ req.add_field("Content-Type", "application/json")
32
+ req.add_field("User-Agent", "Sigimera Ruby Client v#{Sigimera::VERSION}")
33
+ req.add_field("Authorization", "Basic #{basic_hash}") if basic_hash
34
+
35
+ http.request(req)
36
+ end
37
+
21
38
  # HEAD endpoint
22
39
  #
23
40
  # @param [String] endpoint The endpoint that should be called.
@@ -44,8 +61,6 @@ module Sigimera
44
61
  http.ca_file = CACERT_FILE
45
62
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
46
63
  http.verify_depth = 5
47
- else
48
- raise "Please use a secure SSL connection and the right root certificate. If you experience problems please contact support@sigimera.org."
49
64
  end
50
65
 
51
66
  return uri, http
@@ -1,9 +1,6 @@
1
+ # encoding: UTF-8
1
2
  module Sigimera
2
- # Part of the Sigimera Platform
3
- #
4
- # Author:: Alex Oberhauser (mailto:alex.oberhauser@sigimera.org)
5
- # Copyright:: Copyright (c) 2012 Sigimera
6
- # License:: Closed Source
3
+ # Module that encapsulates the version number.
7
4
  module VERSION
8
5
  # The major version number that changes only if incompatibility with
9
6
  # the previous version was introduced.
@@ -16,7 +13,7 @@ module Sigimera
16
13
  TINY = 1
17
14
 
18
15
  # The extra string marks the version as beta, alpha, rcX, ...
19
- EXTRA = "rc2"
16
+ EXTRA = nil
20
17
 
21
18
  # Concatenates the version to a point separated string
22
19
  STRING = [MAJOR, MINOR, TINY].join('.')
data/sigimera.gemspec CHANGED
@@ -1,24 +1,26 @@
1
- $:.push File.expand_path("../lib", __FILE__)
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
4
 
3
5
  require "sigimera/version"
4
6
 
5
- Gem::Specification.new do |s|
6
- s.name = "sigimera"
7
- s.version = Sigimera::VERSION
8
- s.authors = [ "Alex Oberhauser" ]
9
- s.email = [ "alex.oberhauser@sigimera.org" ]
10
- s.licenses = [ "MIT" ]
11
- s.homepage = "https://github.com/Sigimera/sigimera-ruby-client"
12
- s.summary = "This is a ruby library that encapsulates access to the Sigimera REST API."
13
- s.description = "This is a ruby library that encapsulates access to the Sigimera REST API."
14
- s.files = `git ls-files`.split("\n")
15
- s.require_paths = [ "lib" ]
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "sigimera"
9
+ gem.version = Sigimera::VERSION
10
+ gem.authors = [ "Alex Oberhauser" ]
11
+ gem.email = [ "alex.oberhauser@sigimera.org" ]
12
+ gem.licenses = [ "MIT" ]
13
+ gem.homepage = "https://github.com/Sigimera/sigimera-ruby-client"
14
+ gem.summary = "This is the official ruby library for the Sigimera REST API."
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
+ gem.files = `git ls-files`.split("\n")
17
+ gem.require_paths = [ "lib" ]
16
18
 
17
- s.add_runtime_dependency "json"
18
- s.add_runtime_dependency "nokogiri" # XML Parsing
19
+ gem.add_runtime_dependency "json"
20
+ gem.add_runtime_dependency "nokogiri" # XML Parsing
19
21
 
20
- s.add_development_dependency "rake"
21
- s.add_development_dependency "rspec"
22
- s.add_development_dependency "spork"
23
- s.add_development_dependency "simplecov"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec"
24
+ gem.add_development_dependency "spork"
25
+ gem.add_development_dependency "simplecov"
24
26
  end
@@ -0,0 +1,125 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ describe Sigimera::Client do
5
+
6
+ before(:all) do
7
+ auth_token = ENV['AUTH_TOKEN']
8
+ if auth_token
9
+ @client = Sigimera::Client.new(auth_token = auth_token)
10
+ else
11
+ pending "Plese specify ENV['AUTH_TOKEN']"
12
+ end
13
+ end
14
+
15
+ it "#get_latest_crises" do
16
+ crises = @client.get_latest_crises
17
+ crises.class.should eql(Array)
18
+ crises.size.should == 10
19
+ crises.each do |crisis|
20
+ crisis.class.should eql(Hash)
21
+ crisis['_id'].class.should eql(String)
22
+ crisis['_id'].should_not be_empty
23
+ end
24
+ end
25
+
26
+ it "#get_latest_crises({ :type => 'earthquakes' })" do
27
+ sleep 1 # Respect the courtesy limit and wait for one second
28
+ crises = @client.get_latest_crises({ :type => "earthquakes" })
29
+ crises.class.should eql(Array)
30
+ crises.size.should == 10
31
+ crises.each do |crisis|
32
+ crisis['dc_subject'].first.should eql("earthquake")
33
+ crisis.class.should eql(Hash)
34
+ crisis['_id'].class.should eql(String)
35
+ crisis['_id'].should_not be_empty
36
+ end
37
+ end
38
+
39
+ it "#get_latest_crises({ :type => 'floods' })" do
40
+ sleep 1 # Respect the courtesy limit and wait for one second
41
+ crises = @client.get_latest_crises({ :type => "floods" })
42
+ crises.class.should eql(Array)
43
+ crises.size.should == 10
44
+ crises.each do |crisis|
45
+ crisis['dc_subject'].first.should eql("flood")
46
+ crisis.class.should eql(Hash)
47
+ crisis['_id'].class.should eql(String)
48
+ crisis['_id'].should_not be_empty
49
+ end
50
+ end
51
+
52
+ it "#get_latest_crises({ :type => 'cyclones' })" do
53
+ sleep 1 # Respect the courtesy limit and wait for one second
54
+ crises = @client.get_latest_crises({ :type => "cyclones" })
55
+ crises.class.should eql(Array)
56
+ crises.size.should == 10
57
+ crises.each do |crisis|
58
+ crisis['dc_subject'].sort.last.should eql("tropical cyclones")
59
+ crisis.class.should eql(Hash)
60
+ crisis['_id'].class.should eql(String)
61
+ crisis['_id'].should_not be_empty
62
+ end
63
+ end
64
+
65
+ it "#get_latest_crises({ :type => 'volcanoes' })" do
66
+ sleep 1 # Respect the courtesy limit and wait for one second
67
+ crises = @client.get_latest_crises({ :type => "volcanoes" })
68
+ crises.class.should eql(Array)
69
+ crises.size.should > 1
70
+ crises.each do |crisis|
71
+ crisis.class.should eql(Hash)
72
+ crisis['_id'].class.should eql(String)
73
+ crisis['_id'].should_not be_empty
74
+ end
75
+ end
76
+
77
+ it "#get_latest_crises({ :type => 'volcanoes', :output => 'short' })" do
78
+ sleep 1 # Respect the courtesy limit and wait for one second
79
+ crises = @client.get_latest_crises({ :type => "volcanoes", :output => "short" })
80
+ crises.class.should eql(Array)
81
+ crises.size.should > 1
82
+ crises.each do |crisis|
83
+ crisis.class.should eql(Hash)
84
+ crisis['_id'].class.should eql(String)
85
+ crisis['_id'].should_not be_empty
86
+ end
87
+ end
88
+
89
+ it "#get_latest_crises({ :type => 'not_available' })" do
90
+ sleep 1 # Respect the courtesy limit and wait for one second
91
+ crises = @client.get_latest_crises({ :type => "not_available" })
92
+ crises.class.should eql(NilClass)
93
+ end
94
+
95
+ it "#get_crisis(identifier)" do
96
+ sleep 1 # Respect the courtesy limit and wait for one second
97
+ id = "a8763f7e2c432ebe897a68706dcf8dd49243774d"
98
+ crisis = @client.get_crisis(id)
99
+ crisis.class.should eql(Hash)
100
+ crisis['_id'].should eql(id)
101
+ crisis['dc_title'].should eql("Green flood alert in Australia")
102
+ crisis['dc_subject'].class.should eql(Array)
103
+ crisis['dc_subject'].size.should > 0
104
+
105
+ sleep 1 # Respect the courtesy limit and wait for one second
106
+ crisis = @client.get_crisis("")
107
+ crisis.class.should eql(NilClass)
108
+
109
+ sleep 1 # Respect the courtesy limit and wait for one second
110
+ crisis = @client.get_crisis(nil)
111
+ crisis.class.should eql(NilClass)
112
+ end
113
+
114
+ it "#get_crisis(identifier, { :output => 'short' })" do
115
+ sleep 1 # Respect the courtesy limit and wait for one second
116
+ id = "a8763f7e2c432ebe897a68706dcf8dd49243774d"
117
+ crisis = @client.get_crisis(id, { :output => 'short' })
118
+ crisis.class.should eql(Hash)
119
+ crisis['_id'].should eql(id)
120
+ crisis['subject'].class.should eql(String)
121
+ crisis['subject'].should eql("flood")
122
+ crisis['dc_title'].should eql("Green flood alert in Australia")
123
+ end
124
+
125
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ describe Sigimera::Client do
5
+
6
+ before(:all) do
7
+ @username = ENV['USERNAME']
8
+ @password = ENV['PASSWORD']
9
+ end
10
+
11
+ it ".get_auth_token(username, password)" do
12
+ if @username and @password
13
+ auth_token = Sigimera::Client.get_auth_token(username = @username, password = @password)
14
+ auth_token.class.should eql(String)
15
+ auth_token.should_not be_empty
16
+ else
17
+ pending "Please specify ENV['USERNAME'] and ENV['PASSWORD']"
18
+ end
19
+ end
20
+
21
+ it ".get_api_version" do
22
+ api_version = Sigimera::Client.get_api_version
23
+ api_version.class.should eql(String)
24
+ api_version.should start_with("1.")
25
+ end
26
+
27
+ it ".get_public_crises" do
28
+ crises = Sigimera::Client.get_public_crises
29
+ crises.class.should eql(Array)
30
+ crises.size.should == 10
31
+ crises.each do |crisis|
32
+ crisis.class.should eql(Hash)
33
+ crisis['_id'].class.should eql(String)
34
+ crisis['_id'].should_not be_empty
35
+ end
36
+ end
37
+
38
+ it ".get_public_rss_feed" do
39
+ crises = Sigimera::Client.get_public_rss_feed
40
+ crises.class.should eql(Nokogiri::XML::Document)
41
+ crises.xpath("/rss/channel/link/text()").to_s.should eql("http://www.sigimera.org/")
42
+ crises.xpath("/rss/channel/item").size.should == 10
43
+ end
44
+
45
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+
4
+ describe Sigimera::Client do
5
+
6
+ before(:all) do
7
+ auth_token = ENV['AUTH_TOKEN']
8
+ if auth_token
9
+ sleep 1 # Respect the courtesy limit and wait for one second
10
+ @client = Sigimera::Client.new(auth_token = auth_token)
11
+ else
12
+ pending "Plese specify ENV['AUTH_TOKEN']"
13
+ end
14
+ end
15
+
16
+ it "#get_crises_stat" do
17
+ crises_stat = @client.get_crises_stat
18
+ crises_stat['first_crisis_at'].should eql("2012-03-07T00:00:00Z")
19
+ crises_stat['total_crises'].class.should eql(Fixnum)
20
+ end
21
+
22
+ it "#get_user_stat" do
23
+ sleep 1 # Respect the courtesy limit and wait for one second
24
+ user_stat = @client.get_user_stat
25
+ number_of_calls = user_stat['api_calls']['number_of_calls']
26
+ number_of_calls.should > 0
27
+
28
+ sleep 1 # Respect the courtesy limit and wait for one second
29
+ second_user_stat = @client.get_user_stat
30
+ second_user_stat['api_calls']['number_of_calls'].should >= (number_of_calls + 1)
31
+ end
32
+
33
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,9 @@ require 'spork'
2
2
 
3
3
  Spork.prefork do
4
4
  require 'simplecov'
5
- SimpleCov.start
5
+ SimpleCov.start do
6
+ add_filter 'spec'
7
+ end
6
8
 
7
9
  RSpec.configure do |config|
8
10
  config.mock_with :rspec
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sigimera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.rc2
5
- prerelease: 6
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alex Oberhauser
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-24 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -107,8 +107,9 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
- description: This is a ruby library that encapsulates access to the Sigimera REST
111
- API.
110
+ description: This is the official ruby library for the Sigimera REST API. It encapsulates
111
+ the authentication process in a secure way and simplifies the access to the Crises
112
+ Information Platform.
112
113
  email:
113
114
  - alex.oberhauser@sigimera.org
114
115
  executables: []
@@ -128,7 +129,9 @@ files:
128
129
  - lib/sigimera/http_helper.rb
129
130
  - lib/sigimera/version.rb
130
131
  - sigimera.gemspec
131
- - spec/api/client_spec.rb
132
+ - spec/api/client_crises_spec.rb
133
+ - spec/api/client_static_spec.rb
134
+ - spec/api/client_stats_spec.rb
132
135
  - spec/spec_helper.rb
133
136
  homepage: https://github.com/Sigimera/sigimera-ruby-client
134
137
  licenses:
@@ -145,17 +148,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
148
  version: '0'
146
149
  segments:
147
150
  - 0
148
- hash: -3216827614524362085
151
+ hash: -1539845786022213272
149
152
  required_rubygems_version: !ruby/object:Gem::Requirement
150
153
  none: false
151
154
  requirements:
152
- - - ! '>'
155
+ - - ! '>='
153
156
  - !ruby/object:Gem::Version
154
- version: 1.3.1
157
+ version: '0'
158
+ segments:
159
+ - 0
160
+ hash: -1539845786022213272
155
161
  requirements: []
156
162
  rubyforge_project:
157
163
  rubygems_version: 1.8.24
158
164
  signing_key:
159
165
  specification_version: 3
160
- summary: This is a ruby library that encapsulates access to the Sigimera REST API.
166
+ summary: This is the official ruby library for the Sigimera REST API.
161
167
  test_files: []
@@ -1,120 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Sigimera::Client do
4
-
5
- before(:all) do
6
- ENV['AUTH_TOKEN'].should_not be_empty
7
- @auth_token = ENV['AUTH_TOKEN']
8
- end
9
-
10
- it ".get_api_version" do
11
- api_version = Sigimera::Client.get_api_version
12
- api_version.class.should eql(String)
13
- api_version.should start_with("1.")
14
- end
15
-
16
- it ".get_public_crises" do
17
- crises = Sigimera::Client.get_public_crises
18
- crises.class.should eql(Array)
19
- crises.size.should == 10
20
- crises.each do |crisis|
21
- crisis.class.should eql(Hash)
22
- crisis['_id'].class.should eql(String)
23
- crisis['_id'].should_not be_empty
24
- end
25
- end
26
-
27
- it ".get_public_rss_feed" do
28
- crises = Sigimera::Client.get_public_rss_feed
29
- crises.class.should eql(Nokogiri::XML::Document)
30
- crises.xpath("/rss/channel/link/text()").to_s.should eql("http://www.sigimera.org/")
31
- crises.xpath("/rss/channel/item").size.should == 10
32
- end
33
-
34
- it "#get_latest_crises" do
35
- client = Sigimera::Client.new(auth_token = @auth_token)
36
- crises = client.get_latest_crises
37
- crises.class.should eql(Array)
38
- crises.size.should == 10
39
- crises.each do |crisis|
40
- crisis.class.should eql(Hash)
41
- crisis['_id'].class.should eql(String)
42
- crisis['_id'].should_not be_empty
43
- end
44
- end
45
-
46
- it "#get_latest_crises(type = 'earthquakes')" do
47
- sleep 1 # Respect the courtesy limit and wait for one second
48
- client = Sigimera::Client.new(auth_token = @auth_token)
49
- crises = client.get_latest_crises(type = "earthquakes")
50
- crises.class.should eql(Array)
51
- crises.size.should == 10
52
- crises.each do |crisis|
53
- crisis['dc_subject'].first.should eql("earthquake")
54
- crisis.class.should eql(Hash)
55
- crisis['_id'].class.should eql(String)
56
- crisis['_id'].should_not be_empty
57
- end
58
- end
59
-
60
- it "#get_latest_crises(type = 'floods')" do
61
- sleep 1 # Respect the courtesy limit and wait for one second
62
- client = Sigimera::Client.new(auth_token = @auth_token)
63
- crises = client.get_latest_crises(type = "floods")
64
- crises.class.should eql(Array)
65
- crises.size.should == 10
66
- crises.each do |crisis|
67
- crisis['dc_subject'].first.should eql("flood")
68
- crisis.class.should eql(Hash)
69
- crisis['_id'].class.should eql(String)
70
- crisis['_id'].should_not be_empty
71
- end
72
- end
73
-
74
- it "#get_latest_crises(type = 'cyclones')" do
75
- sleep 1 # Respect the courtesy limit and wait for one second
76
- client = Sigimera::Client.new(auth_token = @auth_token)
77
- crises = client.get_latest_crises(type = "cyclones")
78
- crises.class.should eql(Array)
79
- crises.size.should == 10
80
- crises.each do |crisis|
81
- crisis['dc_subject'].sort.last.should eql("tropical cyclones")
82
- crisis.class.should eql(Hash)
83
- crisis['_id'].class.should eql(String)
84
- crisis['_id'].should_not be_empty
85
- end
86
- end
87
-
88
- it "#get_latest_crises(type = 'volcanoes')" do
89
- sleep 1 # Respect the courtesy limit and wait for one second
90
- client = Sigimera::Client.new(auth_token = @auth_token)
91
- crises = client.get_latest_crises(type = "volcanoes")
92
- crises.class.should eql(Array)
93
- crises.size.should > 1
94
- crises.each do |crisis|
95
- crisis.class.should eql(Hash)
96
- crisis['_id'].class.should eql(String)
97
- crisis['_id'].should_not be_empty
98
- end
99
- end
100
-
101
- it "#get_crises_stat" do
102
- sleep 1 # Respect the courtesy limit and wait for one second
103
- client = Sigimera::Client.new(auth_token = @auth_token)
104
- crises_stat = client.get_crises_stat
105
- crises_stat['first_crisis_at'].should eql("2012-03-07T00:00:00Z")
106
- crises_stat['total_crises'].class.should eql(Fixnum)
107
- end
108
-
109
- it "#get_user_stat" do
110
- sleep 1 # Respect the courtesy limit and wait for one second
111
- client = Sigimera::Client.new(auth_token = @auth_token)
112
- user_stat = client.get_user_stat
113
- number_of_calls = user_stat['api_calls']['number_of_calls']
114
- number_of_calls.should > 0
115
-
116
- sleep 1 # Respect the courtesy limit and wait for one second
117
- second_user_stat = client.get_user_stat
118
- second_user_stat['api_calls']['number_of_calls'].should == (number_of_calls + 1)
119
- end
120
- end