sp_client 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTE5OWNhN2IzNTQ4NjAzOWQ0NzA4NTA1ZjA4MDkyY2Y4YjJmNzUyZA==
5
+ data.tar.gz: !binary |-
6
+ OTM0NDVkZmM2ZmM0YzNmNzA5MzQ3YjM3OTA3YzI2ZmZkNGJhYWRiZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDhmZThiYTNmNjNlN2M1NzU3NGI0NzFkODI4MWM4N2FmNDhiMjI0YmQ2Y2E4
10
+ YWUzZjAwOGNmYTc3MzcxNjllY2EzNTZlYjY0MTE3NmEzMThiOGU4OTdmNzlm
11
+ MzY5YzE5MzkzNjZhOGMzZjI4MWI4NjRkYTcxNGRmZmFkMTUzMWY=
12
+ data.tar.gz: !binary |-
13
+ M2I3MTIzNjRlNGY3OTRiYmFkNDUwYTdkNDM4YWNjZjEwYjFiNDVjZTMzYTRk
14
+ ZTBhYWI2NWNiOTU5ZjRlYzM4Nzc1MzlmNDI0YWY5OWExZDBkYTE3MmRjYTNj
15
+ ZGQ4MWI1MDUyZjBkOTM2N2FmOGFhMWI0MmFmZjc0NGE0NDBkODc=
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ Gemfile.lock
2
+ vendor/ruby
3
+ .bundle/config
4
+ .bundle/install.log
5
+ .idea
6
+ *.iml
7
+ .project
8
+ spec/dummy
9
+
10
+ *.gem
11
+ *.rbc
12
+ .bundle
13
+ .config
14
+ .yardoc
15
+ InstalledFiles
16
+ _yardoc
17
+ coverage
18
+ doc/
19
+ lib/bundler/man
20
+ pkg
21
+ rdoc
22
+ spec/reports
23
+ test/tmp
24
+ test/version_tmp
25
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development do
5
+ gem 'rake'
6
+ gem 'rspec'
7
+ gem 'webmock'
8
+ 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
+ sp_client
2
+ ======================
3
+
4
+ Ruby client for interacting with the Summer Project tool
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,76 @@
1
+ require 'rest-client'
2
+ require 'oj'
3
+ require 'retryable'
4
+
5
+ module SummerProject
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 Summer Project with your access_token.' unless SummerProject.access_token
31
+
32
+ path ||= default_path
33
+ url = SummerProject.base_url
34
+ url += '/' unless url.last == '/'
35
+ url += path
36
+ case method
37
+ when :post
38
+ RestClient.post(url, params, authorization: "Bearer #{SummerProject.access_token}", :timeout => -1) { |response, request, result, &block|
39
+ handle_response(response, request, result)
40
+ }
41
+ when :put
42
+ RestClient.put(url, params, authorization: "Bearer #{SummerProject.access_token}", :timeout => -1) { |response, request, result, &block|
43
+ handle_response(response, request, result)
44
+ }
45
+ else
46
+ RestClient::Request.execute(:method => method, :url => url, :headers => {params: params, authorization: "Bearer #{SummerProject.access_token}"}, :timeout => -1) { |response, request, result, &block|
47
+ handle_response(response, request, result)
48
+ }
49
+ end
50
+ end
51
+
52
+ def self.handle_response(response, request, result)
53
+ case response.code
54
+ when 200..299
55
+ Oj.load(response)
56
+ when 400
57
+ raise RestClient::BadRequest, response
58
+ when 500
59
+ raise RestClient::InternalServerError, response
60
+ else
61
+ puts response.inspect
62
+ puts request.inspect
63
+ raise result.inspect
64
+ end
65
+ end
66
+
67
+ def self.default_path
68
+ to_s.split('::').last.underscore.pluralize
69
+ end
70
+
71
+ def self.path_with_id(id)
72
+ "#{default_path}/#{id}"
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,6 @@
1
+ module SummerProject
2
+ class Ministry < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module SummerProject
2
+ class Person < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,5 @@
1
+ module SummerProject
2
+ class Project < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module SummerProject
2
+ class Region < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module SummerProject
2
+ class Team < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ module SummerProject
2
+ class User < Base
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,4 @@
1
+ module SummerProject
2
+ VERSION = "1.0.0"
3
+ end
4
+
@@ -0,0 +1,22 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'summer_project/base'
3
+
4
+ Dir[File.dirname(__FILE__) + '/summer_project/*.rb'].each do |file|
5
+ require file
6
+ end
7
+
8
+ module SummerProject
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://sp.campuscrusadeforchrist.com/"
18
+ end
19
+
20
+ end
21
+ end
22
+
data/sp_client.gemspec ADDED
@@ -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 'summer_project/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sp_client"
8
+ gem.version = SummerProject::VERSION
9
+ gem.authors = ["Kenneth John Balgos"]
10
+ gem.email = ["kennethjohnbalgos@gmail.com"]
11
+ gem.description = %q{This gem wraps an API for the Summer Project.}
12
+ gem.summary = %q{Push and pull data from the Summer Project}
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
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sp_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenneth John Balgos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-08 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 Summer Project.
70
+ email:
71
+ - kennethjohnbalgos@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - lib/summer_project.rb
82
+ - lib/summer_project/base.rb
83
+ - lib/summer_project/ministry.rb
84
+ - lib/summer_project/person.rb
85
+ - lib/summer_project/project.rb
86
+ - lib/summer_project/region.rb
87
+ - lib/summer_project/team.rb
88
+ - lib/summer_project/user.rb
89
+ - lib/summer_project/version.rb
90
+ - sp_client.gemspec
91
+ homepage: ''
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Push and pull data from the Summer Project
114
+ test_files: []