sigimera 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/MIT-LICENSE +20 -0
- data/README.md +80 -0
- data/Rakefile +16 -0
- data/certs/cacert.crt +41 -0
- data/lib/sigimera/client.rb +57 -0
- data/lib/sigimera/http_helper.rb +54 -0
- data/lib/sigimera/version.rb +42 -0
- data/lib/sigimera.rb +19 -0
- data/sigimera.gemspec +23 -0
- data/spec/api/client_spec.rb +100 -0
- data/spec/spec_helper.rb +9 -0
- metadata +145 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@sigimera
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sigimera (0.0.1.rc1)
|
5
|
+
json
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
json (1.7.5)
|
13
|
+
nokogiri (1.5.5)
|
14
|
+
rake (10.0.2)
|
15
|
+
rspec (2.12.0)
|
16
|
+
rspec-core (~> 2.12.0)
|
17
|
+
rspec-expectations (~> 2.12.0)
|
18
|
+
rspec-mocks (~> 2.12.0)
|
19
|
+
rspec-core (2.12.0)
|
20
|
+
rspec-expectations (2.12.0)
|
21
|
+
diff-lcs (~> 1.1.3)
|
22
|
+
rspec-mocks (2.12.0)
|
23
|
+
spork (0.9.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
rake
|
30
|
+
rspec
|
31
|
+
sigimera!
|
32
|
+
spork
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Alex Oberhauser
|
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.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
Sigimera Client
|
2
|
+
===============
|
3
|
+
|
4
|
+
This repository includes a ruby client library for the REST API under http://api.sigimera.org.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Install _sigimera_ manually from command line:
|
11
|
+
|
12
|
+
```sh
|
13
|
+
gem install sigimera
|
14
|
+
```
|
15
|
+
|
16
|
+
Add _sigimera_ to your Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'sigimera'
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
This examples are only a short outline how to use the library. For more
|
27
|
+
information read the documentation, checkout the rspecs or look into the
|
28
|
+
source code. To use the library include or execute the following lines:
|
29
|
+
|
30
|
+
```sh
|
31
|
+
irb
|
32
|
+
>> require "sigimera"
|
33
|
+
>> puts Sigimera::Client.get_api_version
|
34
|
+
>> puts Sigimera::Client.get_public_crises
|
35
|
+
>> puts Sigimera::Client.get_public_rss_feed
|
36
|
+
|
37
|
+
# see http://api.sigimera.org/dashboard
|
38
|
+
>> client = Sigimera::Client.new("YourSecretToken")
|
39
|
+
>> puts client.get_latest_crises
|
40
|
+
>> puts client.get_latest_crises(type = "earthquakes")
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
Start RSpec Tests
|
45
|
+
-----------------
|
46
|
+
|
47
|
+
In order to test this library with the help of rspec you have get first an
|
48
|
+
_authentication token_ under the [Developer Dashboard](http://api.sigimera.org/dashboard)
|
49
|
+
|
50
|
+
```sh
|
51
|
+
export AUTH_TOKEN=YourSecretToken
|
52
|
+
rake spec
|
53
|
+
```
|
54
|
+
|
55
|
+
API Documentation
|
56
|
+
-----------------
|
57
|
+
|
58
|
+
This library simplifies the Sigimera REST API. If you want learn more about
|
59
|
+
this API you can use the following links:
|
60
|
+
|
61
|
+
* [Quickstart](http://api.sigimera.org/quickstart)
|
62
|
+
* [FAQ](http://api.sigimera.org/faq)
|
63
|
+
* [Developer Dashboard](http://api.sigimera.org/dashboard): You must be logged
|
64
|
+
in.
|
65
|
+
|
66
|
+
|
67
|
+
License
|
68
|
+
-------
|
69
|
+
|
70
|
+
(c) 2012 by [Sigimera](http://www.sigimera.org),
|
71
|
+
published under MIT license.
|
72
|
+
|
73
|
+
|
74
|
+
Warranty
|
75
|
+
--------
|
76
|
+
|
77
|
+
This software is provided "as is" and without any express or implied
|
78
|
+
warranties, including, without limitation, the implied warranties of
|
79
|
+
merchantibility and fitness for a particular purpose.
|
80
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
12
|
+
t.fail_on_error = true
|
13
|
+
t.rspec_opts = "--colour --format documentation -b"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :spec
|
data/certs/cacert.crt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290
|
3
|
+
IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB
|
4
|
+
IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA
|
5
|
+
Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO
|
6
|
+
BgNVBAoTB1Jvb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEi
|
7
|
+
MCAGA1UEAxMZQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJ
|
8
|
+
ARYSc3VwcG9ydEBjYWNlcnQub3JnMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC
|
9
|
+
CgKCAgEAziLA4kZ97DYoB1CW8qAzQIxL8TtmPzHlawI229Z89vGIj053NgVBlfkJ
|
10
|
+
8BLPRoZzYLdufujAWGSuzbCtRRcMY/pnCujW0r8+55jE8Ez64AO7NV1sId6eINm6
|
11
|
+
zWYyN3L69wj1x81YyY7nDl7qPv4coRQKFWyGhFtkZip6qUtTefWIonvuLwphK42y
|
12
|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@
|
|
1
|
+
require "json"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module Sigimera
|
5
|
+
# The main class that could be used to access the REST API
|
6
|
+
class Client
|
7
|
+
include Sigimera::HttpHelper
|
8
|
+
|
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
|
14
|
+
end
|
15
|
+
|
16
|
+
# This method returns current API version. For this purpose
|
17
|
+
# the X-API-Version HTTP header is read out.
|
18
|
+
#
|
19
|
+
# @return [String] The first found version string of the API
|
20
|
+
def self.get_api_version
|
21
|
+
client = Sigimera::Client.new
|
22
|
+
response = client.head("/public/crises")
|
23
|
+
response.get_fields("X-API-Version").first.to_s if response.key?("X-API-Version")
|
24
|
+
end
|
25
|
+
|
26
|
+
# This method returns the latest 10 crises, but needs no
|
27
|
+
# authentication token.
|
28
|
+
#
|
29
|
+
# @return [Array] Returns an array of crises objects in JSON
|
30
|
+
def self.get_public_crises
|
31
|
+
client = Sigimera::Client.new
|
32
|
+
response = client.get("/public/crises")
|
33
|
+
JSON.parse response.body if response
|
34
|
+
end
|
35
|
+
|
36
|
+
# This method returns the latest 10 crises as RSS feed,
|
37
|
+
# but needs no authentication token.
|
38
|
+
#
|
39
|
+
# @return [Nokogiri::XML::Document] Returns an a nokogiri xml document
|
40
|
+
def self.get_public_rss_feed
|
41
|
+
client = Sigimera::Client.new
|
42
|
+
response = client.get("/public/crises.rss")
|
43
|
+
Nokogiri::XML(response.body) if response
|
44
|
+
end
|
45
|
+
|
46
|
+
# This method returns the latest 10 crises.
|
47
|
+
#
|
48
|
+
# @param [String] type The crises type, e.g. earthquake, flood, cyclone, volcanoe
|
49
|
+
# @return [Array] Returns an array of crises objects in JSON
|
50
|
+
def get_latest_crises(type = nil)
|
51
|
+
endpoint = "/v1/crises?auth_token=#{@auth_token}"
|
52
|
+
endpoint += "&type=#{type}" if type
|
53
|
+
response = self.get(endpoint)
|
54
|
+
JSON.parse response.body if response
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
module Sigimera
|
4
|
+
# Encapsulates the low level HTTP(S) calls.
|
5
|
+
module HttpHelper
|
6
|
+
|
7
|
+
# GET endpoint
|
8
|
+
#
|
9
|
+
# @param [String] endpoint The endpoint that should be called.
|
10
|
+
# @return [Net::HTTPResponse] The HTTP response object
|
11
|
+
def get(endpoint)
|
12
|
+
uri, http = get_connection(endpoint)
|
13
|
+
|
14
|
+
req = Net::HTTP::Get.new("#{uri.path}?#{uri.query}")
|
15
|
+
req.add_field("Content-Type", "application/json")
|
16
|
+
req.add_field("User-Agent", "Sigimera Ruby Client v#{Sigimera::VERSION}")
|
17
|
+
|
18
|
+
http.request(req)
|
19
|
+
end
|
20
|
+
|
21
|
+
# HEAD endpoint
|
22
|
+
#
|
23
|
+
# @param [String] endpoint The endpoint that should be called.
|
24
|
+
# @return [Net::HTTPResponse] The HTTP response object
|
25
|
+
def head(endpoint)
|
26
|
+
uri, http = get_connection(endpoint)
|
27
|
+
|
28
|
+
req = Net::HTTP::Head.new("#{uri.path}?#{uri.query}")
|
29
|
+
req.add_field("User-Agent", "Sigimera Ruby Client v#{Sigimera::VERSION}")
|
30
|
+
|
31
|
+
http.request(req)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# @param [String] endpoint The endpoint that should be called.
|
37
|
+
# @return [Array] First is the URI and second the HTTP object.
|
38
|
+
def get_connection(endpoint)
|
39
|
+
uri = URI(API_HOST + endpoint)
|
40
|
+
|
41
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
42
|
+
http.use_ssl = (uri.scheme == 'https')
|
43
|
+
if (File.file?(CACERT_FILE) && http.use_ssl?)
|
44
|
+
http.ca_file = CACERT_FILE
|
45
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
46
|
+
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
|
+
end
|
50
|
+
|
51
|
+
return uri, http
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
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
|
7
|
+
module VERSION
|
8
|
+
# The major version number that changes only if incompatibility with
|
9
|
+
# the previous version was introduced.
|
10
|
+
MAJOR = 0
|
11
|
+
|
12
|
+
# The minor version number indicates that new features were added.
|
13
|
+
MINOR = 0
|
14
|
+
|
15
|
+
# The tiny number stands for bug fixes.
|
16
|
+
TINY = 1
|
17
|
+
|
18
|
+
# The extra string marks the version as beta, alpha, rcX, ...
|
19
|
+
EXTRA = "rc1"
|
20
|
+
|
21
|
+
# Concatenates the version to a point separated string
|
22
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
23
|
+
STRING << ".#{EXTRA}" if EXTRA
|
24
|
+
|
25
|
+
##
|
26
|
+
# @return [String]
|
27
|
+
def self.to_s()
|
28
|
+
STRING
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# @return [String]
|
33
|
+
def self.to_str()
|
34
|
+
STRING
|
35
|
+
end
|
36
|
+
##
|
37
|
+
# @return [Array(Integer, Integer, Integer)]
|
38
|
+
def self.to_a()
|
39
|
+
[MAJOR, MINOR, TINY]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/sigimera.rb
ADDED
@@ -0,0 +1,19 @@
|
|
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
|
+
# The Sigimera REST API Host
|
11
|
+
API_HOST = "https://api.sigimera.org"
|
12
|
+
|
13
|
+
# The used SSL certificate for the HTTPS encrpytion
|
14
|
+
CACERT_FILE = File.expand_path("../../certs/cacert.crt", __FILE__)
|
15
|
+
end
|
16
|
+
|
17
|
+
require "sigimera/version"
|
18
|
+
require "sigimera/http_helper"
|
19
|
+
require "sigimera/client"
|
data/sigimera.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require "sigimera/version"
|
4
|
+
|
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" ]
|
16
|
+
|
17
|
+
s.add_dependency "json"
|
18
|
+
s.add_dependency "nokogiri" # XML Parsing
|
19
|
+
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
s.add_development_dependency "spork"
|
23
|
+
end
|
@@ -0,0 +1,100 @@
|
|
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
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sigimera
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.rc1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Oberhauser
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: spork
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: This is a ruby library that encapsulates access to the Sigimera REST
|
95
|
+
API.
|
96
|
+
email:
|
97
|
+
- alex.oberhauser@sigimera.org
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- .rvmrc
|
104
|
+
- Gemfile
|
105
|
+
- Gemfile.lock
|
106
|
+
- MIT-LICENSE
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- certs/cacert.crt
|
110
|
+
- lib/sigimera.rb
|
111
|
+
- lib/sigimera/client.rb
|
112
|
+
- lib/sigimera/http_helper.rb
|
113
|
+
- lib/sigimera/version.rb
|
114
|
+
- sigimera.gemspec
|
115
|
+
- spec/api/client_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
homepage: https://github.com/Sigimera/sigimera-ruby-client
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: 4279827424064706299
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>'
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.3.1
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.8.24
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: This is a ruby library that encapsulates access to the Sigimera REST API.
|
145
|
+
test_files: []
|