infobase 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 040843aa673b8f2e264d77aaf6ca34c71e39fe71
4
+ data.tar.gz: cec550748f27363d85fa97d50cacadb442b23248
5
+ SHA512:
6
+ metadata.gz: 69b9589809024e9c92323ed6bf6e3e0f63dd83d6a62ba39a60cc26a5b276d0a8d3034f874b4eb7f5f16cd5151e580854fe64494b8f2956f9dfe95cd3f86b1862
7
+ data.tar.gz: 0f91e1b7a8e18dd0cbcccfbbd9b018e3dcee7ce055942d21d7138e7f7e2107ebc1a425e83be27cd68315b50cc3f7e41e4daedfbbd46091e7da2fb4b72ae723b7
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/ruby
19
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in infobase.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'webmock'
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 CruGlobal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ infobase_client
2
+ ======================
3
+
4
+ Ruby client for interacting with the Infobase
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'infobase/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "infobase"
8
+ gem.version = Infobase::VERSION
9
+ gem.authors = ["Josh Starcher"]
10
+ gem.email = ["josh.starcher@gmail.com"]
11
+ gem.description = %q{This gem wraps an API for the Infobase.}
12
+ gem.summary = %q{Push and pull data from the Infobase}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('rest-client', '~> 1.6.7')
21
+ gem.add_dependency('oj', '~> 2.1.0')
22
+ gem.add_dependency('activesupport')
23
+ gem.add_dependency('retryable-rb', '~> 1.1.0')
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ module Infobase
2
+ class Activity < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,79 @@
1
+ require 'rest-client'
2
+ require 'oj'
3
+ require 'retryable'
4
+
5
+ module Infobase
6
+ class Base
7
+
8
+ def self.find(id, params = {})
9
+ request(:get, params, path_with_id(id))
10
+ end
11
+
12
+ def self.get(params = {})
13
+ request(:get, params)
14
+ end
15
+
16
+ def self.post(params = {})
17
+ request(:post, params)
18
+ end
19
+
20
+ def self.put(id, params = {})
21
+ request(:put, params, path_with_id(id))
22
+ end
23
+
24
+ def self.delete(id)
25
+ request(:delete, {}, path_with_id(id))
26
+ end
27
+
28
+
29
+ def self.request(method, params, path = nil)
30
+ raise 'You need to configure Infobase with your access_token.' unless Infobase.access_token
31
+
32
+ path ||= default_path
33
+ url = Infobase.base_url
34
+ url += '/' unless url.last == '/'
35
+ url += path
36
+
37
+ case method
38
+ when :post
39
+ RestClient.post(url, params, authorization: "Bearer #{Infobase.access_token}", :timeout => -1) { |response, request, result, &block|
40
+ handle_response(response, request, result)
41
+ }
42
+ when :put
43
+ RestClient.put(url, params, authorization: "Bearer #{Infobase.access_token}", :timeout => -1) { |response, request, result, &block|
44
+ handle_response(response, request, result)
45
+ }
46
+ else
47
+ RestClient::Request.execute(:method => method, :url => url, :headers => {params: params, authorization: "Bearer #{Infobase.access_token}"}, :timeout => -1) { |response, request, result, &block|
48
+ handle_response(response, request, result)
49
+ }
50
+ end
51
+ end
52
+
53
+ def self.handle_response(response, request, result)
54
+ case response.code
55
+ when 200..299
56
+ Oj.load(response)
57
+ when 400
58
+ raise RestClient::BadRequest, response
59
+ when 500
60
+ raise RestClient::InternalServerError, response
61
+ else
62
+ puts response.inspect
63
+ puts request.inspect
64
+ raise result.inspect
65
+ end
66
+ end
67
+
68
+ def self.default_path
69
+ to_s.split('::').last.underscore.pluralize
70
+ end
71
+
72
+ def self.path_with_id(id)
73
+ "#{default_path}/#{id}"
74
+ end
75
+
76
+ end
77
+ end
78
+
79
+
@@ -0,0 +1,6 @@
1
+ module Infobase
2
+ class Ministry < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module Infobase
2
+ class Person < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module Infobase
2
+ class Region < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,5 @@
1
+ module Infobase
2
+ class Statistic < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module Infobase
2
+ class Team < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module Infobase
2
+ class User < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,4 @@
1
+ module Infobase
2
+ VERSION = "1.0.0"
3
+ end
4
+
data/lib/infobase.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'infobase/base'
3
+
4
+ Dir[File.dirname(__FILE__) + '/infobase/*.rb'].each do |file|
5
+ require file
6
+ end
7
+
8
+ module Infobase
9
+ class << self
10
+ attr_accessor :base_url, :access_token
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
16
+ def base_url
17
+ @base_url ||= "https://infobase.uscm.org/"
18
+ end
19
+
20
+ end
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infobase
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Starcher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: retryable-rb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
69
+ description: This gem wraps an API for the Infobase.
70
+ email:
71
+ - josh.starcher@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - global_registry.gemspec
82
+ - lib/infobase.rb
83
+ - lib/infobase/activity.rb
84
+ - lib/infobase/base.rb
85
+ - lib/infobase/ministry.rb
86
+ - lib/infobase/person.rb
87
+ - lib/infobase/region.rb
88
+ - lib/infobase/statistic.rb
89
+ - lib/infobase/team.rb
90
+ - lib/infobase/user.rb
91
+ - lib/infobase/version.rb
92
+ homepage: ''
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Push and pull data from the Infobase
115
+ test_files: []