platform_lib 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/platform_lib.rb +3 -0
- data/lib/platform_lib/account_service.rb +50 -0
- data/lib/platform_lib/business_service.rb +70 -0
- data/lib/platform_lib/filemanagement_service.rb +44 -0
- data/lib/platform_lib/service_base.rb +13 -0
- data/lib/platform_lib/version.rb +1 -1
- data/lib/platform_lib/web_helper.rb +13 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45543706933ad779646842d51b6ae58fdf15eb35
|
4
|
+
data.tar.gz: 5dfb6465c06b8ec8004538c494e03e3b96c6a0d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae540e30f67334cb2492b302a86444cd5856846dbf61446e8230687de69d97ec537e3094f657ab3a50d61a3ab6142538e48c12847c1a86c7109c38b65e13213
|
7
|
+
data.tar.gz: 259ae7b71c9a3c3de1307a0af0d9e1e6f2427ce402e99adad7bdd581003d96e8dfd0d5e0051c10b844fb8170357c478e4e5cbe84e964b01ffcd238ad63e2ff1a
|
data/lib/platform_lib.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require "platform_lib/version"
|
2
|
+
require "platform_lib/business_service"
|
2
3
|
require "platform_lib/data_service"
|
3
4
|
require "platform_lib/media_service"
|
4
5
|
require "platform_lib/task_service"
|
6
|
+
require "platform_lib/account_service"
|
7
|
+
require "platform_lib/filemanagement_service"
|
5
8
|
|
6
9
|
# scripts
|
7
10
|
require "scripts/sync_guid_with_id"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'platform_lib/service_base'
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
# Public: A wrapper around the Account Data Service
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
#
|
10
|
+
# # the preferred method
|
11
|
+
# service = PlatformLib::DataService.new("user", "pass").account_service
|
12
|
+
#
|
13
|
+
# # direct instantiation
|
14
|
+
# service = PlatformLib::AccountService.new("auth_token")
|
15
|
+
#
|
16
|
+
class AccountService
|
17
|
+
include ServiceBase
|
18
|
+
|
19
|
+
END_POINT = "https://mps.theplatform.com/data/Account"
|
20
|
+
|
21
|
+
# Public: Creates a new instance
|
22
|
+
#
|
23
|
+
# auth_token - the authentication token to be used
|
24
|
+
def initialize(auth_token)
|
25
|
+
@auth_token = auth_token
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Queries the account end point
|
29
|
+
#
|
30
|
+
# params - an optional hash of parameters (query string)
|
31
|
+
# block - an optional block to be called for each item returned
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
#
|
35
|
+
# items = account_service.get_account_items(range: "1-10")
|
36
|
+
#
|
37
|
+
# account_service.get_account_items(byCustomValue: "{test}{val}") do |item|
|
38
|
+
# puts item.title
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# Returns the items supplied from the service
|
42
|
+
def get_account_items(params = {}, &block)
|
43
|
+
if block.nil?
|
44
|
+
get_entries(END_POINT, params)
|
45
|
+
else
|
46
|
+
get_entries(END_POINT, params, &block)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "json"
|
2
|
+
require "hashie"
|
3
|
+
require "platform_lib/web_helper"
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
class BusinessService
|
7
|
+
|
8
|
+
def initialize(username, password)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
@auth_token = nil
|
12
|
+
|
13
|
+
@services = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method_name, *args)
|
17
|
+
if method_name =~ /^(.*)_service$/
|
18
|
+
service_by_name($1)
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def sign_out
|
25
|
+
return if @auth_token.nil?
|
26
|
+
|
27
|
+
url = AUTH_URL_FORMAT.sub(/ACTION/, 'signOut')
|
28
|
+
url << "&_token=#{@auth_token}"
|
29
|
+
uri = URI.parse(url)
|
30
|
+
|
31
|
+
response = WebHelper::get(uri, :user => @username, :pass => @password)
|
32
|
+
@auth_token = nil
|
33
|
+
@services.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
AUTH_URL_FORMAT = "https://identity.auth.theplatform.com"
|
39
|
+
AUTH_URL_FORMAT << "/idm/web/Authentication/ACTION?schema=1.0&form=json"
|
40
|
+
|
41
|
+
def service_by_name(name)
|
42
|
+
|
43
|
+
# we've already got an instance
|
44
|
+
service = @services[name]
|
45
|
+
|
46
|
+
if service.nil?
|
47
|
+
# create a new service
|
48
|
+
sign_in
|
49
|
+
|
50
|
+
class_name = "#{name.capitalize}Service"
|
51
|
+
service = PlatformLib.const_get(class_name).new(@auth_token)
|
52
|
+
@services[name] = service
|
53
|
+
end
|
54
|
+
|
55
|
+
if block_given?
|
56
|
+
yield(service)
|
57
|
+
else
|
58
|
+
service
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def sign_in
|
63
|
+
uri = URI.parse(AUTH_URL_FORMAT.sub(/ACTION/, 'signIn'))
|
64
|
+
response = WebHelper::get(uri, user: @username, pass: @password)
|
65
|
+
|
66
|
+
response_object = Hashie::Mash.new(JSON.parse(response))
|
67
|
+
@auth_token = response_object.signInResponse.token
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'platform_lib/service_base'
|
4
|
+
|
5
|
+
module PlatformLib
|
6
|
+
# Public: A wrapper around the File Management Business Service
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
#
|
10
|
+
# # the preferred method
|
11
|
+
# service = PlatformLib::BusinessService.new("user", "pass").filemanagement_service
|
12
|
+
#
|
13
|
+
# # direct instantiation
|
14
|
+
# service = PlatformLib::FileManagementService.new("auth_token")
|
15
|
+
#
|
16
|
+
class FilemanagementService
|
17
|
+
include ServiceBase
|
18
|
+
|
19
|
+
END_POINT = "https://fms.theplatform.com/web/FileManagement"
|
20
|
+
|
21
|
+
# Public: Creates a new instance
|
22
|
+
#
|
23
|
+
# auth_token - the authentication token to be used
|
24
|
+
def initialize(auth_token)
|
25
|
+
@auth_token = auth_token
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Resets the task end point
|
29
|
+
#
|
30
|
+
# params - an optional hash of parameters (query string)
|
31
|
+
# block - an optional block to be called for each item returned
|
32
|
+
#
|
33
|
+
# Examples:
|
34
|
+
#
|
35
|
+
# resetTask = filemanagement_service.resetTask(taskId, params)
|
36
|
+
#
|
37
|
+
#
|
38
|
+
# Returns an empty response if successful
|
39
|
+
def resetTask(taskId, params)
|
40
|
+
data = { :resetTask => { :taskId => taskId } }
|
41
|
+
post_data(END_POINT, params, data)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -65,6 +65,19 @@ module PlatformLib
|
|
65
65
|
WebHelper::put(uri, body)
|
66
66
|
end
|
67
67
|
|
68
|
+
def post_data(end_point, params = {}, data)
|
69
|
+
ensure_auth_param(params)
|
70
|
+
|
71
|
+
uri = URI.parse("#{end_point}?#{URI.encode_www_form(params)}")
|
72
|
+
puts uri.to_s
|
73
|
+
body = "#{JSON.generate(data)}"
|
74
|
+
|
75
|
+
puts body
|
76
|
+
|
77
|
+
WebHelper::post(uri, body)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
68
81
|
private
|
69
82
|
|
70
83
|
def ensure_auth_param(params)
|
data/lib/platform_lib/version.rb
CHANGED
@@ -33,6 +33,19 @@ module PlatformLib
|
|
33
33
|
http.request(request)
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.post(uri, body)
|
37
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
+
if uri.scheme == "https"
|
39
|
+
http.use_ssl = true
|
40
|
+
end
|
41
|
+
|
42
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
43
|
+
request.content_type = "application/json"
|
44
|
+
request.body = body
|
45
|
+
|
46
|
+
http.request(request)
|
47
|
+
end
|
48
|
+
|
36
49
|
private
|
37
50
|
|
38
51
|
def self.set_auth(request, auth)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platform_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Muto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -126,7 +126,10 @@ files:
|
|
126
126
|
- Rakefile
|
127
127
|
- bin/tp_lib
|
128
128
|
- lib/platform_lib.rb
|
129
|
+
- lib/platform_lib/account_service.rb
|
130
|
+
- lib/platform_lib/business_service.rb
|
129
131
|
- lib/platform_lib/data_service.rb
|
132
|
+
- lib/platform_lib/filemanagement_service.rb
|
130
133
|
- lib/platform_lib/media_service.rb
|
131
134
|
- lib/platform_lib/service_base.rb
|
132
135
|
- lib/platform_lib/task_service.rb
|
@@ -159,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
162
|
version: '0'
|
160
163
|
requirements: []
|
161
164
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.2.
|
165
|
+
rubygems_version: 2.2.2
|
163
166
|
signing_key:
|
164
167
|
specification_version: 4
|
165
168
|
summary: Work with ThePlatform Data Services
|