gram_v1_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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 53c450edb7a70a6e8b710ac4720b3d9f6b08de05
4
+ data.tar.gz: 93196cffe6b60ad1865406aa8864bb203bf60825
5
+ SHA512:
6
+ metadata.gz: c2771ad464bb0e936ed7eb9125b671f68f928306be0032f25d7d128d2d66691a26e9d7148eaa34d96ce2d618b5804b5087821081dd2a80d0b42d0db119663a63
7
+ data.tar.gz: 76a37475fa62e260874b664213191c66a702525a32d6554c2f2ed69afcc11d056efe46b0917a6e10e8ff7b136cbed67e2d6a3092d1c9be62e849813187f7edbe
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gram_v1_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexandre Narbonne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # GramV1Client
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'gram_v1_client'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gram_v1_client
18
+
19
+ ## Setup
20
+
21
+ Before being used GramV1Client must be configured. In Rails app, put it in an Initializer.
22
+
23
+ ```ruby
24
+ GramV1Client.configure do |c|
25
+ # Base URI used to access GrAM API
26
+ c.site="http://my_site.org/api/v1/"
27
+ # Username provided by Gadz.org
28
+ c.user="my_user"
29
+ # Password provided by Gadz.org
30
+ c.password="my_password"
31
+ # If your app use a proxy to access net, put it here
32
+ #c.proxy="my_proxy"
33
+ end
34
+ ```
35
+ ## Usage
36
+
37
+ This client client is based on the active_ressource gem. [Read its documentation](https://github.com/rails/activeresource) for informations about interacting with ressources
38
+ It provides access to the following resources on GrAM API :
39
+
40
+ - Account
41
+ - Profile
42
+ - Email
43
+ - Search
44
+
45
+ ###Account
46
+ ####Find
47
+ ```ruby
48
+ account = GramV1Client::Account.find("john.doe.ext")
49
+ puts account.firstname
50
+ puts account.lastname
51
+ #=> John
52
+ #=> Doe
53
+ ```
54
+ ####Update
55
+ ```ruby
56
+ account = GramV1Client::Account.find("john.doe.ext")
57
+ account.firstname = "Johny"
58
+ account.save
59
+ ```
60
+
61
+ ####Create
62
+ ```ruby
63
+ account = GramV1Client::Account.new(hruid: "john.doe.ext", firstname: "John", lastname: "Doe")
64
+ account.save
65
+ ```
66
+ Or
67
+ ```ruby
68
+ account = GramV1Client::Account.create(hruid: "john.doe.ext", firstname: "John", lastname: "Doe")
69
+ ```
70
+
71
+ ###Profile
72
+ ####Find
73
+ ```ruby
74
+ profile = GramV1Client::Profile.find("john.doe.ext")
75
+ puts account.firstname
76
+ puts account.lastname
77
+ #=> John
78
+ #=> Doe
79
+ ```
80
+
81
+ ###Email
82
+ ####Find
83
+ ```ruby
84
+ email = GramV1Client::Email.find("john.doe@gadz.org")
85
+ ```
86
+
87
+ ###Search
88
+ This resource is used to search for accounts
89
+
90
+ You can use the generic search
91
+ ```ruby
92
+ account = GramV1Client::Search.where(:idSoce => "84185")
93
+ ```
94
+
95
+ Or you can use helper methods :
96
+ ```ruby
97
+ account = GramV1Client::Search.search_by_hruid("john.doe.ext")
98
+ account = GramV1Client::Search.search_by_id_soce("84185")
99
+ account = GramV1Client::Search.search_by_email("john.doe@gadz.org")
100
+ account = GramV1Client::Search.search_by_alias("john.doe")
101
+ ```
102
+ ## Development
103
+
104
+ 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.
105
+
106
+ 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).
107
+
108
+ ## Contributing
109
+
110
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Zooip/gram_v1_client.
111
+
112
+
113
+ ## License
114
+
115
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
116
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gram_v1_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_v1_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gram_v1_client"
8
+ spec.version = GramV1Client::VERSION
9
+ spec.authors = ["Alexandre Narbonne"]
10
+ spec.email = ["alexandre.narbonne@gadz.org"]
11
+
12
+ spec.summary = "Ruby client for the Gadz.org API GrAMv1"
13
+ spec.homepage = "https://github.com/Zooip/gram_v1_client"
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,13 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require 'gram_v1_client/configuration'
4
+ require 'gram_v1_client/json_formater'
5
+ require 'gram_v1_client/base'
6
+ require 'gram_v1_client/account'
7
+ require 'gram_v1_client/profile'
8
+ #require 'gram_v1_client/email'
9
+ require 'gram_v1_client/search'
10
+ require 'gram_v1_client/version'
11
+
12
+ class GramV1Client
13
+ end
@@ -0,0 +1,28 @@
1
+ #/lib/GramAccount.rb
2
+ #!/bin/env ruby
3
+ # encoding: utf-8
4
+
5
+ # exemple de recherche par hruid
6
+ # GramAccount.find("alexandra.narbonnette.ext")
7
+
8
+ require 'active_resource'
9
+ require 'gram_v1_client/base'
10
+ class GramV1Client::Account < GramV1Client::Base
11
+ self.element_name = "accounts"
12
+
13
+ ##
14
+ #Overwrite find_single from ActiveResource::Base to be able to use gram api (/accounts suffix)
15
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
16
+ def self.element_path(id, prefix_options = {}, query_options = nil)
17
+ id += "/accounts"
18
+ super(id, prefix_options, query_options)
19
+ end
20
+
21
+ ##
22
+ #Overwrite to_param from ActiveResource::Base to be able to use gram api (id = hruid)
23
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
24
+ def to_param
25
+ self.hruid
26
+ end
27
+
28
+ end
@@ -0,0 +1,57 @@
1
+ #/lib/GramAccount.rb
2
+ #!/bin/env ruby
3
+ # encoding: utf-8
4
+
5
+
6
+ require 'active_resource'
7
+ class GramV1Client::Base < ActiveResource::Base
8
+
9
+ # This is set to enable Configuration change at runtime.
10
+
11
+ class << self
12
+ def site
13
+ if GramV1Client.configuration.site
14
+ if super.to_s != URI.parse(GramV1Client.configuration.site).to_s
15
+ reload_config
16
+ end
17
+ end
18
+ super
19
+ end
20
+
21
+ def user()
22
+ if GramV1Client.configuration.user
23
+ if super.to_s != GramV1Client.configuration.user
24
+ reload_config
25
+ end
26
+ end
27
+ super
28
+ end
29
+
30
+ def password()
31
+ if GramV1Client.configuration.password
32
+ if super.to_s != GramV1Client.configuration.password
33
+ reload_config
34
+ end
35
+ end
36
+ super
37
+ end
38
+
39
+ def proxy()
40
+ if GramV1Client.configuration.proxy
41
+ if super.to_s != URI.parse(GramV1Client.configuration.proxy).to_s
42
+ reload_config
43
+ end
44
+ end
45
+ super
46
+ end
47
+
48
+
49
+ def reload_config
50
+ self.site= GramV1Client.configuration.site
51
+ self.user= GramV1Client.configuration.user
52
+ self.password=GramV1Client.configuration.password
53
+ self.proxy=GramV1Client.configuration.proxy
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,28 @@
1
+ class GramV1Client
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,34 @@
1
+ #/lib/GramAccount.rb
2
+ #!/bin/env ruby
3
+ # encoding: utf-8
4
+
5
+
6
+ # exemple de recherche par email
7
+ # GramEmail.find("monEmail@gadz.org")
8
+
9
+ require 'active_resource'
10
+ class GramV1Client::Email < GramV1Client::Base
11
+ self.element_name = "emails"
12
+ self.collection_name = "emails"
13
+ self.format = GramV1Client::JsonFormatter.new(self.collection_name)
14
+
15
+
16
+ #Overwrite find_single from ActiveResource::Base to be able to use gram api (/accounts suffix)
17
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
18
+ def self.element_path(id, prefix_options = {}, query_options = nil)
19
+ id += "/accounts"
20
+ super(id, prefix_options, query_options)
21
+ end
22
+
23
+ def collection_path(prefix_options = {}, query_options = nil)
24
+ id += "/accounts"
25
+ super(id, prefix_options, query_options)
26
+ end
27
+
28
+ #Overwrite to_param from ActiveResource::Base to be able to use gram api (id = hruid)
29
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
30
+ def to_param
31
+ self.hruid
32
+ end
33
+
34
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_resource'
2
+
3
+ class GramV1Client::JsonFormatter
4
+ include ActiveResource::Formats::JsonFormat
5
+
6
+ attr_reader :collection_name
7
+
8
+ def initialize(collection_name)
9
+ @collection_name = collection_name.to_s
10
+ end
11
+
12
+ def decode(json)
13
+ remove_root(ActiveSupport::JSON.decode(json))
14
+ end
15
+
16
+ private
17
+
18
+ def remove_root(data)
19
+ if data.is_a?(Hash) && data[collection_name]
20
+ data[collection_name]
21
+ else
22
+ data.first
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ #/lib/GramAccount.rb
2
+ #!/bin/env ruby
3
+ # encoding: utf-8
4
+
5
+ require 'active_resource'
6
+ class GramProfile < GramV1Client::Base
7
+ self.element_name = "profiles"
8
+
9
+ #Overwrite find_single from ActiveResource::Base to be able to use gram api (/accounts suffix)
10
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
11
+ def self.element_path(id, prefix_options = {}, query_options = nil)
12
+ id += "/profile"
13
+ super(id, prefix_options, query_options)
14
+ end
15
+
16
+ #Overwrite to_param from ActiveResource::Base to be able to use gram api (id = hruid)
17
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
18
+ def to_param
19
+ self.hruid
20
+ end
21
+ end
@@ -0,0 +1,43 @@
1
+ #/lib/GramAccount.rb
2
+ #!/bin/env ruby
3
+ # encoding: utf-8
4
+
5
+
6
+ # exemple pour rechercher avec un idSoce
7
+ #GramSearch.where(:idSoce => "84185")
8
+
9
+
10
+ require 'active_resource'
11
+ class GramV1Client::Search < GramV1Client::Base
12
+ self.element_name = "search"
13
+ self.collection_name = "search/uniq"
14
+
15
+
16
+ #Overwrite find_single from ActiveResource::Base to be able to use gram api (/accounts suffix)
17
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
18
+ def self.element_path(id, prefix_options = {}, query_options = nil)
19
+ #query_options = "uniq.json?idSoce=" + id
20
+ id = "uniq"
21
+ super(id, prefix_options, query_options)
22
+ end
23
+
24
+ def collection_path(prefix_options = {}, query_options = nil)
25
+ id = "uniq"
26
+ super(id, prefix_options, query_options)
27
+ end
28
+
29
+ #Overwrite to_param from ActiveResource::Base to be able to use gram api (id = hruid)
30
+ #https://github.com/rails/activeresource/blob/master/lib/active_resource/base.rb#L991
31
+ def to_param
32
+ self.hruid
33
+ end
34
+
35
+
36
+ class << self
37
+ [:hruid,:email,:idSoce,:alias].each do |param|
38
+ define_method("by_#{param.to_s.underscore}") do |q|
39
+ self.where(param => q)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ class GramV1Client
2
+
3
+ VERSION = "1.0.0"
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gram_v1_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Narbonne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeresource
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - alexandre.narbonne@gadz.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - gram_v1_client.gemspec
86
+ - lib/gram_v1_client.rb
87
+ - lib/gram_v1_client/account.rb
88
+ - lib/gram_v1_client/base.rb
89
+ - lib/gram_v1_client/configuration.rb
90
+ - lib/gram_v1_client/email.rb
91
+ - lib/gram_v1_client/json_formater.rb
92
+ - lib/gram_v1_client/profile.rb
93
+ - lib/gram_v1_client/search.rb
94
+ - lib/gram_v1_client/version.rb
95
+ homepage: https://github.com/Zooip/gram_v1_client
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ allowed_push_host: https://rubygems.org
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby client for the Gadz.org API GrAMv1
120
+ test_files: []
121
+ has_rdoc: