ruby-swift 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +101 -0
  4. data/lib/ruby_swift.rb +94 -0
  5. metadata +60 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26f071b6b85789f1f09f967888fed8cca992a3a6
4
+ data.tar.gz: ddd106544903cd824eee8640221a592d648305d1
5
+ SHA512:
6
+ metadata.gz: 97b53f999942ad4a5f46e73508504e88173ab6f1bc1707e4379a4ff5abfbad5b7e6499b7f7ea079e87720e86e0ac2fdca258707b35bee80bf28104494be4a77f
7
+ data.tar.gz: 0256813bff346f7da02bf5fbfff0bc7bbc1423a02404f94f2c992eb136e282fd83ed78e14d8be691a8da0ddf7fef0ae730b5c3d56e09daab0942a630a16c931d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Andrew Buntine
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 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,
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 THE
21
+ SOFTWARE.
@@ -0,0 +1,101 @@
1
+ RubySwift
2
+ =========
3
+
4
+ A ruby wrapper of the [Swift Digital Suite Mail House API](https://suite.swiftdigital.com.au/login).
5
+
6
+ This is currently a relatively crude wrapper and does not tidy responses from Swift a lot.
7
+
8
+ INSTALLATION
9
+ ------------
10
+ You can install the library via Rubygems:
11
+
12
+ $ gem install ruby-swift
13
+
14
+ Or within your Gemfile if you're using Bundler:
15
+
16
+ gem "ruby-swift"
17
+
18
+ USAGE
19
+ -----
20
+ Initialize the connection:
21
+
22
+ ```ruby
23
+ swift = RubySwift.new("API_PASSWORD")
24
+ ```
25
+
26
+ Does a person exist?
27
+
28
+ ```ruby
29
+ swift.person_exists?("you@example.com") # -> true
30
+ ```
31
+
32
+ Read a person:
33
+
34
+ ```ruby
35
+ person = swift.read_person("you@example.com")
36
+ ```
37
+
38
+ Add someone to a mail group:
39
+
40
+ ```ruby
41
+ swift.add_group_member("you@example.com", "Group Name") # -> "0"
42
+ ```
43
+
44
+ Remove someone from a mail group:
45
+
46
+ ```ruby
47
+ swift.remove_group_member("you@example.com", "Group Name") # -> "0"
48
+ ```
49
+
50
+ Create a person:
51
+
52
+ ```ruby
53
+ swift.write_person(email: "me@example.com", first_name: "Dennis", last_name: "Ritchie") # -> "0"
54
+ ```
55
+
56
+ Update person:
57
+
58
+ ```ruby
59
+ swift.update_person(email: "you@example.com", first_name: "Donald", last_name: "Knuth") # -> "0"
60
+ ```
61
+
62
+ Create or update existing person:
63
+
64
+ ```ruby
65
+ swift.write_or_update_person(email: "me@example.com", first_name: "Dennis", last_name: "Ritchie") # -> "0"
66
+ ```
67
+
68
+ Create a group:
69
+
70
+ ```ruby
71
+ swift.write_group("Group name") # -> "0"
72
+ ```
73
+
74
+ Read all groups:
75
+
76
+ ```ruby
77
+ groups = swift.read_groups
78
+ ```
79
+
80
+ Read all members of a group:
81
+
82
+ ```ruby
83
+ people = swift.read_persons("Group Name")
84
+ ```
85
+
86
+ Remove a group:
87
+
88
+ ```ruby
89
+ swift.remove_group("Group Name") # -> "0"
90
+ ```
91
+
92
+ Remove a person:
93
+
94
+ ```ruby
95
+ swift.remove_person("you@example.com") # -> "0"
96
+ ```
97
+
98
+ TODO
99
+ ----
100
+ * Tidy up responses (Hashie?)
101
+ * Return true/false instead of "0" for write actions
@@ -0,0 +1,94 @@
1
+ class RubySwift
2
+
3
+ require "savon"
4
+
5
+ def initialize(password, namespace="ns1", http_adapter=:net_http)
6
+ HTTPI.adapter = http_adapter
7
+
8
+ @password = password
9
+ @client = Savon.client(endpoint: "http://suite.peoplelogic.com.au/server/includes/apis/soap.php",
10
+ namespace: namespace,
11
+ convert_request_keys_to: :none)
12
+ end
13
+
14
+ def person_exists?(email)
15
+ read_person(email).is_a?(Hash)
16
+ end
17
+
18
+ def write_or_update_person(fields)
19
+ if person_exists?(fields[:email])
20
+ update_person(fields[:email], fields.reject { |k,v| k == :email})
21
+ else
22
+ write_person(fields)
23
+ end
24
+ end
25
+
26
+ def read_person(email)
27
+ soap_request("read_person", {email: email})
28
+ end
29
+
30
+ def write_person(fields)
31
+ soap_request("write_person", fields)
32
+ end
33
+
34
+ def read_groups
35
+ soap_request("read_groups")
36
+ end
37
+
38
+ def add_group_member(email, group_name)
39
+ soap_request("add_group_member", {email: email, group_name: group_name})
40
+ end
41
+
42
+ def remove_group_member(email, group_name)
43
+ soap_request("remove_group_member", {email: email, group_name: group_name})
44
+ end
45
+
46
+ def read_persons(group_name)
47
+ soap_request("read_persons", {group_name: group_name})
48
+ end
49
+
50
+ def remove_group(group_name)
51
+ soap_request("remove_group", {group_name: group_name})
52
+ end
53
+
54
+ def remove_person(email)
55
+ soap_request("remove_person", {email: email})
56
+ end
57
+
58
+ def update_person(old_email, fields)
59
+ soap_request("update_person", {email_old: old_email}.merge(fields))
60
+ end
61
+
62
+ def write_group(group_name)
63
+ soap_request("write_group", {group_name: group_name})
64
+ end
65
+
66
+ private
67
+
68
+ # Performs a SOAP request.
69
+ def soap_request(operation, data=nil)
70
+ response = @client.call(operation, xml: request_body(operation, data))
71
+
72
+ tidy_response(response.body)
73
+ end
74
+
75
+ # Generates a raw XML SOAP request document.
76
+ # I need to do it this way because the Swift SOAP server expects a particularly weird XML
77
+ # format that SAvon does not naturally produce.
78
+ def request_body(operation, data)
79
+ "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:pl\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:ns2=\"http://xml.apache.org/xml-soap\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Body><ns1:#{operation}><param0 xsi:type=\"xsd:string\">#{@password}</param0><param1 xsi:type=\"ns2:Map\">#{hash_to_soap(data)}</param1></ns1:#{operation}></SOAP-ENV:Body></SOAP-ENV:Envelope>"
80
+ end
81
+
82
+ def hash_to_soap(data)
83
+ if data
84
+ data.map do |k, v|
85
+ "<item><key xsi:type=\"xsd:string\">#{k}</key><value xsi:type=\"xsd:string\">#{v}</value></item>"
86
+ end.join
87
+ end
88
+ end
89
+
90
+ # Tidies up the response that Swift gives us.
91
+ def tidy_response(response)
92
+ response.to_a[0][1][:return]
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-swift
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Buntine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: savon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A ruby wrapper of the Swift Digital Suite Mail House API (https://suite.swiftdigital.com.au).
28
+ email: bunts@hhd.com.au
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - lib/ruby_swift.rb
36
+ homepage: http://github.com/buntine/ruby-swift
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.2.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A ruby wrapper of the Swift Digital Suite API.
60
+ test_files: []