heroix 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4a626b0bb6cc29165f374538446926680004929
4
+ data.tar.gz: f8cd5cc204af787401cfb68eb7bfd9122c84c459
5
+ SHA512:
6
+ metadata.gz: 62cc251d11d4b14ebcc1106bee0f8fef2b21e0e8b6275c22b70ff35101ed1ad0da99aff03b4b26d58fa4a0ec4d5ce9b9cb210dcc3d1ea30b91a61607660a045d
7
+ data.tar.gz: dd5e41d029a3a7eefac97d83785a166fa4273cafeaf10d7126de3626d8b93ed20b0f6737f9ab372a6884e5bd9e113dcbb65fbc950a7548815dff0ea1840c969f
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+
5
+ Documentation:
6
+ Enabled: false
7
+
8
+ HashSyntax:
9
+ Exclude:
10
+ - '**/*'
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ heroix (0.2.0)
5
+ rest-client (~> 1.6.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.0.0)
11
+ diff-lcs (1.2.5)
12
+ json (1.8.1)
13
+ mime-types (1.25.1)
14
+ parser (2.2.0.pre.3)
15
+ ast (>= 1.1, < 3.0)
16
+ slop (~> 3.4, >= 3.4.5)
17
+ powerpack (0.0.9)
18
+ rainbow (2.0.0)
19
+ rake (10.3.2)
20
+ rdoc (4.1.1)
21
+ json (~> 1.4)
22
+ rest-client (1.6.8)
23
+ mime-types (~> 1.16)
24
+ rdoc (>= 2.4.2)
25
+ rspec (3.0.0)
26
+ rspec-core (~> 3.0.0)
27
+ rspec-expectations (~> 3.0.0)
28
+ rspec-mocks (~> 3.0.0)
29
+ rspec-core (3.0.2)
30
+ rspec-support (~> 3.0.0)
31
+ rspec-expectations (3.0.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.0.0)
34
+ rspec-mocks (3.0.2)
35
+ rspec-support (~> 3.0.0)
36
+ rspec-support (3.0.2)
37
+ rubocop (0.24.1)
38
+ json (>= 1.7.7, < 2)
39
+ parser (>= 2.2.0.pre.3, < 3.0)
40
+ powerpack (~> 0.0.6)
41
+ rainbow (>= 1.99.1, < 3.0)
42
+ ruby-progressbar (~> 1.4)
43
+ ruby-progressbar (1.5.1)
44
+ slop (3.5.0)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.6)
51
+ heroix!
52
+ rake
53
+ rspec
54
+ rubocop
@@ -0,0 +1,3 @@
1
+ # Titanic
2
+
3
+ Heroix client gem
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
5
+
6
+ task default: :rubocop
7
+
8
+ task ci: :rubocop
data/bin/ci ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ bundle install --path ../vendor/bundle
6
+
7
+ bundle exec rake ci
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroix/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heroix"
8
+ spec.version = Heroix::VERSION
9
+ spec.authors = ["Leon Fu", "Marty Zalega", "Mark Ryall"]
10
+ spec.email = ["edh-dev@everydayhero.com.au"]
11
+ spec.summary = %q{Heroix global client}
12
+ spec.description = %q{Heroix global client}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rest-client', '~> 1.6.1'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'rubocop'
27
+ end
@@ -0,0 +1,62 @@
1
+ require 'heroix/version'
2
+ require 'heroix/resource'
3
+
4
+ module Heroix
5
+ class Client < Resource
6
+ def users
7
+ build_resource :users, :user
8
+ end
9
+
10
+ def session
11
+ build_resource :session, :session
12
+ end
13
+
14
+ def organisations
15
+ build_resource :organisations, :organisation
16
+ end
17
+
18
+ def beneficiaries
19
+ build_resource :beneficiaries, :beneficiary
20
+ end
21
+
22
+ def beneficiary_registrations
23
+ build_resource :beneficiary_registrations, :beneficiary_registration
24
+ end
25
+
26
+ def beneficiary_rules
27
+ build_resource :beneficiary_rules, :beneficiary_rule
28
+ end
29
+
30
+ def campaigns
31
+ build_resource :campaigns, :campaign
32
+ end
33
+
34
+ def campaign_peer_to_peers
35
+ build_resource :campaign_peer_to_peers, :campaign_peer_to_peer
36
+ end
37
+
38
+ def organisation_beneficiaries
39
+ build_resource :organisation_beneficiaries, :organisation_beneficiary
40
+ end
41
+
42
+ def campaign_beneficiaries
43
+ build_resource :campaign_beneficiaries, :campaign_beneficiary
44
+ end
45
+
46
+ def microsites
47
+ build_resource :microsites, :microsite
48
+ end
49
+
50
+ def microsite_pages
51
+ build_resource :microsite_pages, :microsite_page
52
+ end
53
+
54
+ private
55
+
56
+ def build_resource(path, namespace)
57
+ Resource.new :url => url_for(path),
58
+ :token => token,
59
+ :namespace => namespace
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,102 @@
1
+ require 'rest_client'
2
+ require 'cgi'
3
+ require 'json'
4
+
5
+ module Heroix
6
+ Unauthorized = RestClient::Unauthorized
7
+
8
+ class Resource
9
+ attr_reader :url, :token, :namespace
10
+
11
+ def initialize(params)
12
+ @url = params[:url]
13
+ @token = params[:token]
14
+ @namespace = params[:namespace]
15
+ end
16
+
17
+ def with_token(value)
18
+ @token = value
19
+ self
20
+ end
21
+
22
+ def resource
23
+ @resource ||= JSON.parse RestClient.get(url)
24
+ end
25
+
26
+ def index(params = {})
27
+ request(:get, url_with_params(params))
28
+ end
29
+
30
+ def show(id)
31
+ request(:get, url_for(id))
32
+ end
33
+
34
+ def create(data)
35
+ request(:post, url, data)
36
+ end
37
+
38
+ def update(id, data)
39
+ request(:put, url_for(id), data)
40
+ end
41
+
42
+ def delete(id)
43
+ request(:delete, url_for(id))
44
+ end
45
+
46
+ protected
47
+
48
+ def url_for(path)
49
+ "#{url}/#{path}"
50
+ end
51
+
52
+ private
53
+
54
+ def url_with_params(params)
55
+ if params.empty?
56
+ url
57
+ else
58
+ "#{url}?#{query_string(params)}"
59
+ end
60
+ end
61
+
62
+ def query_string(params)
63
+ params
64
+ .map { |key, value| "#{escape(key)}=#{escape(value)}" }
65
+ .join('&')
66
+ end
67
+
68
+ def escape(value)
69
+ CGI.escape(value.to_s)
70
+ end
71
+
72
+ def request(method, url, data = nil)
73
+ response = RestClient.send(method, url, *request_args(data))
74
+
75
+ deprecation = response.headers[:x_deprecation]
76
+ puts "[heroix] DEPRECATION WARNING #{deprecation}" if deprecation
77
+
78
+ parse_response response.to_str
79
+ end
80
+
81
+ def parse_response(response)
82
+ return {} if response.empty?
83
+ JSON.parse response
84
+ end
85
+
86
+ def request_args(data)
87
+ headers = { 'Authorization' => "Token token=\"#{token}\"" }
88
+ args = []
89
+
90
+ if data
91
+ args << prepare_data(data)
92
+ headers[:content_type] = :json
93
+ end
94
+ args << headers
95
+ end
96
+
97
+ def prepare_data(data)
98
+ data = { namespace => data } if namespace
99
+ data.to_json
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module Heroix
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'heroix'
2
+ JackAndRose = Heroix
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Leon Fu
8
+ - Marty Zalega
9
+ - Mark Ryall
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-12-18 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 1.6.1
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.6'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.6'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rubocop
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ description: Heroix global client
86
+ email:
87
+ - edh-dev@everydayhero.com.au
88
+ executables:
89
+ - ci
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".rubocop.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - README.md
97
+ - Rakefile
98
+ - bin/ci
99
+ - heroix.gemspec
100
+ - lib/heroix.rb
101
+ - lib/heroix/resource.rb
102
+ - lib/heroix/version.rb
103
+ - lib/jack_and_rose.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Heroix global client
128
+ test_files: []