samenessed 0.1.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: 9f5512c5b141bbeead53191a6ce18ed0f94dbd2e
4
+ data.tar.gz: dda13ca94010023ddaf6269777b8aa6fe25ee498
5
+ SHA512:
6
+ metadata.gz: f80989e0235bc0b8994379ece180d34d0b1372ad152a464a4ae5709d03d8b0e74cba9f154623ca8d141f6a05687648a3058856273becdf805ee7d2bcbf1e827b
7
+ data.tar.gz: b1cdc94b7466aed57bf6dfd1e8d8908db1d8fb3eb7c9ec7405725eb3159d1e7800b35d172387aa1324e5c36b5ac36a0e442949f52e9a724f256a3f13b6d4ffed
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ config/config.yml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in samenessed.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Julian Weber
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Samenessed
2
+
3
+ The samenessed gem enables access to the sameness service ( https://github.com/avarteqgmbh/sameness ) . It provides access to the subject and principal class by connecting the sameness service's api.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'samenessed'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install samenessed
18
+
19
+ ## Prerequisites
20
+
21
+ Ensure to call Samenessed.load_config_file(path_to_your_config_file) before issuing any functions. You can include this line in an initializer wihtin your rails application.
22
+
23
+ ## Usage
24
+
25
+ You can specify the SAMENESSED_ENV environment variable to select the environment for samenessed. The default is 'development'.
26
+
27
+ ### Subjects (Master Identities)
28
+
29
+ #### Create a subject
30
+
31
+ subject = Subject.new(firstname: 'James', lastname: 'Kirk')
32
+ subject.new? # => true
33
+ subject.save # => true
34
+ subject.new # => false
35
+ subject.id # => 1
36
+
37
+ #### Find subjects
38
+
39
+ subject = Subject.find(1)
40
+ subject.firstname # => 'James'
41
+ subject.id # => 1
42
+
43
+ #### Delete a subject
44
+
45
+ subject = Subject.find(1)
46
+ subject.destroy # => true
47
+ subject.exists? # => false
48
+
49
+ #### Update a subject
50
+
51
+ subject = Subject.find(1)
52
+ subject.firstname = 'Ron'
53
+ subject.save # => true
54
+
55
+ ### Principals (Service Identities)
56
+
57
+ Find, delete and update methods are correspond to the method
58
+ descriptions above.
59
+
60
+ #### Create a new Principal
61
+
62
+ subject = Subject.find(1)
63
+ principal = Principal.new(account_type: "jabber", name: "name@jabberhost.de", remote_id: 123, subject_id: subject.id)
64
+ principal.exists? # => false
65
+ principal.save # => true
66
+ principal.exists? # => true
67
+
68
+
69
+ #### Retrieve Principals of a subject
70
+
71
+ subject = Subject.find(1)
72
+ subject.principals
73
+ subject.principals.count # => 2
74
+
75
+ #### Retrieve Account data from another account
76
+ to_account_type = "harvest"
77
+ from_account_type = "jabber"
78
+ from_account_name = "john@jabber.johndoe.com"
79
+ Principal.fetch_identity(from_account_type, from_account_name, to_account_type) # => "johnd@company.com"
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Run a pry console session'
4
+ task :console do
5
+ exec("pry -r ./lib/samenessed.rb")
6
+ end
7
+
8
+ task c: :console
@@ -0,0 +1,9 @@
1
+ production:
2
+ site: http://sameness.de.a9sapp.eu/
3
+ user: prod_user
4
+ password: prod_password
5
+
6
+ development:
7
+ site: http://sameness2.de.a9sapp.eu/
8
+ user: dev_user
9
+ password: dev_password
@@ -0,0 +1,29 @@
1
+ module Samenessed
2
+ class Principal < ActiveResource::Base
3
+ self.site = Samenessed.site
4
+ self.user = Samenessed.user
5
+ self.password = Samenessed.password
6
+
7
+ belongs_to :subject, :class_name => 'Samenessed::Subject'
8
+
9
+ # Retrieves the target identity for the given origin data.
10
+ # Returns a string with the target identity or nil if no matching principal could be found
11
+ # Arguments:
12
+ # - from_account_type : The type of the origin account
13
+ # - from_account_name : The id of the origin account
14
+ # - to_account_type : The type of the target account
15
+ def self.fetch_identity(from_account_type, from_account_name, to_account_type)
16
+ raise ArgumentError, "No from account type given!" if from_account_type.nil?
17
+ raise ArgumentError, "No from account name given!" if from_account_name.nil?
18
+ raise ArgumentError, "No to account type given!" if to_account_type.nil?
19
+
20
+ h = Principal.get(:fetch, { :from => { :account_type => from_account_type, :name => from_account_name }, :to => { :account_type => to_account_type } } )
21
+
22
+ unless h.nil?
23
+ h["name"]
24
+ else
25
+ nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Samenessed
2
+ class Subject < ActiveResource::Base
3
+ self.site = Samenessed.site
4
+ self.user = Samenessed.user
5
+ self.password = Samenessed.password
6
+
7
+ has_many :principals, :class_name => 'Samenessed::Principal'
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Samenessed
2
+ VERSION = "0.1.0"
3
+ end
data/lib/samenessed.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "samenessed/version"
2
+ require "active_resource"
3
+
4
+ module Samenessed
5
+ autoload :Subject, File.expand_path('../samenessed/subject', __FILE__)
6
+ autoload :Principal, File.expand_path('../samenessed/principal', __FILE__)
7
+
8
+ @site
9
+ @user
10
+ @password
11
+
12
+ def self.load_config_file(filepath)
13
+ config = YAML.load(File.read(filepath))[Samenessed.env]
14
+ @site = config["site"]
15
+ @user = config["user"]
16
+ @password = config["password"]
17
+ return config
18
+ end
19
+
20
+ def self.load_config_from_hash(hash)
21
+ @site = hash[:site]
22
+ @user = hash[:user]
23
+ @password = hash[:password]
24
+ return hash
25
+ end
26
+
27
+ def self.env
28
+ env = ENV['SAMENESSED_ENV'] || 'development'
29
+ env
30
+ end
31
+
32
+ def self.site
33
+ @site
34
+ end
35
+
36
+ def self.user
37
+ @user
38
+ end
39
+
40
+ def self.password
41
+ @password
42
+ end
43
+ end
@@ -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 'samenessed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "samenessed"
8
+ spec.version = Samenessed::VERSION
9
+ spec.authors = ["Julian Weber"]
10
+ spec.email = ["jweber@anynines.com"]
11
+ spec.description = %q{Samenessed provides access to the sameness service using simple object methods.}
12
+ spec.summary = %q{A sameness access gem.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "pry-debugger"
25
+
26
+ spec.add_dependency 'activeresource'
27
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: samenessed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julian Weber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: pry-debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activeresource
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Samenessed provides access to the sameness service using simple object
84
+ methods.
85
+ email:
86
+ - jweber@anynines.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - config/config.yml.example
97
+ - lib/samenessed.rb
98
+ - lib/samenessed/principal.rb
99
+ - lib/samenessed/subject.rb
100
+ - lib/samenessed/version.rb
101
+ - samenessed.gemspec
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.6
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A sameness access gem.
126
+ test_files: []