gram_v2_client 2.1.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: 980e1bcfb5ad1ea738251c5e8827456c8c108336
4
+ data.tar.gz: c46d443d827940ade078db8a74b74543ad41ccce
5
+ SHA512:
6
+ metadata.gz: caafac5ebb681161edf6aedf30b7ead4c0663096c422c561a5458b2d126eb2b60a9f07834f58f88ec124d2b0403170df280c14ea3d8662d03811a6ab7b04a069
7
+ data.tar.gz: 2bd8ed2585024b6d85acbf51a599911bfb50053c0d665ba9e45144f4b4b25db17b6b6126dc1ae3fd7c208a4a381cc38420569deb87873967d165064ea5f0c887
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ .idea
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ Gemfile.lock
47
+ .ruby-version
48
+ .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gram_v2_client.gemspec
4
+ gemspec
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # GramV2Client
2
+ ## Installation
3
+
4
+ Add this line to your application's Gemfile:
5
+
6
+ ```ruby
7
+ gem 'gram_v2_client', git: 'https://github.com/gadzorg/gram2_api_client_ruby.git'
8
+ ```
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ ## Setup
15
+
16
+ Before being used GramV2Client must be configured. In Rails app, put it in an Initializer.
17
+
18
+ ```ruby
19
+ GramV2Client.configure do |c|
20
+ # Base URI used to access GrAM API
21
+ c.site="http://my_site.org/api/v1/"
22
+ # Username provided by Gadz.org
23
+ c.user="my_user"
24
+ # Password provided by Gadz.org
25
+ c.password="my_password"
26
+ # If your app use a proxy to access net, put it here
27
+ c.proxy="my_proxy"
28
+ end
29
+ GramV2Client.init
30
+
31
+
32
+ ```
33
+
34
+ Tips : you can init a config for the test environment (local instance of gram2_api_server and default admin account) with `GramV2Client.init_test`.
35
+ ## Usage
36
+ This client is based on ActiveRessource thus you can manipulate `account`, `group` and `role` as Ruby objects.
37
+ ### Account
38
+ #### Find
39
+ ```ruby
40
+ # Return all accounts
41
+ GramV2Client::Account.all
42
+
43
+ # Return first account
44
+ GramV2Client::Account.first
45
+
46
+ # Find account with uuid = "c2ce6327-158d-458a-9e76-c89ac9c14a14"
47
+ account = GramV2Client::Account.find("c2ce6327-158d-458a-9e76-c89ac9c14a14")
48
+ puts account.firstname
49
+ puts account.lastname
50
+ #=> John
51
+ #=> Doe
52
+ ````
53
+ #### Update
54
+ ```ruby
55
+ account = GramV2Client::Account.find("c2ce6327-158d-458a-9e76-c89ac9c14a14")
56
+ account.firstname = "Johny"
57
+ account.save
58
+ ````
59
+
60
+ #### Create
61
+ ```ruby
62
+ account = GramV2Client::Account.new(
63
+ firstname: "John",
64
+ lastname: "Doe",
65
+ email: "john.doe@test.test",
66
+ password: "passw0rd",
67
+ is_gadz: false
68
+ )
69
+ account.save
70
+ ````
71
+ Or
72
+ ```ruby
73
+ account = GramV2Client::Account.create(
74
+ firstname: "John",
75
+ lastname: "Doe",
76
+ email: "john.doe@test.test",
77
+ password: "passw0rd",
78
+ is_gadz: false
79
+ )
80
+ ````
81
+
82
+ ### Group
83
+ #### Find
84
+ ```ruby
85
+ # Return all groups
86
+ GramV2Client::Group.all
87
+
88
+ # Return first group
89
+ GramV2Client::Group.first
90
+
91
+ # Find group with uuid = "ffa43f12-f47b-44ea-ad81-f7ede483f394"
92
+ group = GramV2Client::group.find("ffa43f12-f47b-44ea-ad81-f7ede483f394")
93
+ puts group.short_name
94
+ #=> My_group
95
+ ````
96
+
97
+ #### Members
98
+ ```ruby
99
+ # Find members of group with uuid = "ffa43f12-f47b-44ea-ad81-f7ede483f394"
100
+ group = GramV2Client::group.find("ffa43f12-f47b-44ea-ad81-f7ede483f394").account
101
+ # Return Accounts collection
102
+ ````
103
+
104
+ ##### Add/remove member
105
+ ```ruby
106
+ group = GramV2Client::group.find("ffa43f12-f47b-44ea-ad81-f7ede483f394")
107
+ account = GramV2Client::Account.find("c2ce6327-158d-458a-9e76-c89ac9c14a14")
108
+
109
+ # Add account with uuid = "c2ce6327-158d-458a-9e76-c89ac9c14a14" to group with uuid = "ffa43f12-f47b-44ea-ad81-f7ede483f394"
110
+ account.add_to_group(group)
111
+
112
+ # Remove account with uuid = "c2ce6327-158d-458a-9e76-c89ac9c14a14" to group with uuid = "ffa43f12-f47b-44ea-ad81-f7ede483f394"
113
+ account.remove_from_group(group)
114
+
115
+ ````
116
+ #### Role
117
+ Roles management is exactly the same as group management.
118
+ ## Development
119
+
120
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
121
+
122
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
123
+
124
+ ## Contributing
125
+
126
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gadzorg/gram2_api_client_ruby.
127
+
128
+
129
+ ## License
130
+
131
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gram_v2_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gram_v2_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gram_v2_client"
8
+ spec.version = GramV2Client::VERSION
9
+ spec.authors = ["Alexandre Narbonne","Dorian Becker"]
10
+ spec.email = ["alexandre.narbonne@gadz.org", "dorian.becker@gadz.org"]
11
+
12
+ spec.summary = "Ruby client for the Gadz.org API GrAMv2"
13
+ spec.homepage = "https://github.com/gadzorg/gram2_api_client_ruby"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency 'activeresource', "~> 4.0"
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.11"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_resource'
2
+ require 'gram_v2_client/configuration'
3
+ require 'gram_v2_client/base'
4
+ require 'gram_v2_client/account'
5
+ require 'gram_v2_client/group'
6
+ require 'gram_v2_client/role'
7
+ require 'gram_v2_client/version'
8
+
9
+ class GramV2Client
10
+ def self.init_test
11
+ GramV2Client.configure do |c|
12
+ c.site = "http://localhost:3000/api/v2"
13
+ c.user = "admin"
14
+ c.password = "password"
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_resource'
2
+ require 'gram_v2_client/base'
3
+
4
+ class GramV2Client::Account < GramV2Client::Base
5
+
6
+ def add_to_group(group)
7
+ post(self.uuid + "/groups", group_uuid: group.uuid)
8
+ end
9
+
10
+ def remove_from_group(group)
11
+ delete(self.uuid + "/groups/" + group.uuid)
12
+ end
13
+
14
+ def add_role(role)
15
+ post(self.uuid + "/roles", role_uuid: role.uuid)
16
+ end
17
+
18
+ def revoke_role(role)
19
+ delete(self.uuid + "/roles/" + role.uuid)
20
+ end
21
+ end
@@ -0,0 +1,63 @@
1
+ require 'active_resource'
2
+
3
+ class GramV2Client::Base < ActiveResource::Base
4
+ # This is set to enable Configuration change at runtime.
5
+
6
+ def to_param
7
+ uuid
8
+ end
9
+
10
+ class << self
11
+ def site
12
+ if GramV2Client.configuration.site
13
+ if super.to_s != URI.parse(GramV2Client.configuration.site).to_s
14
+ reload_config
15
+ end
16
+ end
17
+ super
18
+ end
19
+
20
+ def user()
21
+ if GramV2Client.configuration.user
22
+ if super.to_s != GramV2Client.configuration.user
23
+ reload_config
24
+ end
25
+ end
26
+ super
27
+ end
28
+
29
+ def password()
30
+ if GramV2Client.configuration.password
31
+ if super.to_s != GramV2Client.configuration.password
32
+ reload_config
33
+ end
34
+ end
35
+ super
36
+ end
37
+
38
+ def proxy()
39
+ if GramV2Client.configuration.proxy
40
+ if super.to_s != URI.parse(GramV2Client.configuration.proxy).to_s
41
+ reload_config
42
+ end
43
+ end
44
+ super
45
+ end
46
+
47
+
48
+ def reload_config
49
+ self.site= GramV2Client.configuration.site
50
+ self.user= GramV2Client.configuration.user
51
+ self.password=GramV2Client.configuration.password
52
+ self.proxy=GramV2Client.configuration.proxy
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+
59
+
60
+
61
+
62
+
63
+
@@ -0,0 +1,28 @@
1
+ class GramV2Client
2
+ class << self
3
+ attr_writer :configuration
4
+
5
+ def configuration
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+
10
+ def configure
11
+ yield(configuration)
12
+ end
13
+ end
14
+
15
+ class Configuration
16
+ attr_accessor :site,
17
+ :user,
18
+ :password,
19
+ :proxy
20
+
21
+ def initialize
22
+ @site = nil
23
+ @user = nil
24
+ @password = nil
25
+ @proxy = nil
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ require 'gram_v2_client/base'
2
+ require 'active_resource'
3
+
4
+
5
+ class GramV2Client::Group < GramV2Client::Base
6
+
7
+ def accounts
8
+ GramV2Client::Account.find(:all, from: self.class.site.to_s + "/groups/" + self.uuid + "/accounts")
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require 'gram_v2_client/base'
2
+ require 'active_resource'
3
+
4
+ class GramV2Client::Role < GramV2Client::Base
5
+ def accounts
6
+ GramV2Client::Account.find(:all, from: self.class.site.to_s + "/roles/" + self.uuid + "/accounts")
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class GramV2Client
2
+
3
+ VERSION = "2.1.0"
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gram_v2_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Narbonne
8
+ - Dorian Becker
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-02-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeresource
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '4.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '4.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.11'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.11'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ description:
71
+ email:
72
+ - alexandre.narbonne@gadz.org
73
+ - dorian.becker@gadz.org
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".idea/vcs.xml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - gram_v2_client.gemspec
86
+ - lib/gram_v2_client.rb
87
+ - lib/gram_v2_client/account.rb
88
+ - lib/gram_v2_client/base.rb
89
+ - lib/gram_v2_client/configuration.rb
90
+ - lib/gram_v2_client/group.rb
91
+ - lib/gram_v2_client/role.rb
92
+ - lib/gram_v2_client/version.rb
93
+ homepage: https://github.com/gadzorg/gram2_api_client_ruby
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby client for the Gadz.org API GrAMv2
118
+ test_files: []
119
+ has_rdoc: