ruby-cleverdome 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-cleverdome.rb +29 -5
- data/lib/ruby-cleverdome/multipart.rb +81 -0
- metadata +34 -1
data/lib/ruby-cleverdome.rb
CHANGED
@@ -2,19 +2,24 @@ require 'nokogiri'
|
|
2
2
|
require 'savon'
|
3
3
|
require 'uuid'
|
4
4
|
require 'signed_xml'
|
5
|
+
require 'mime/types'
|
6
|
+
require 'ruby-cleverdome/multipart'
|
7
|
+
require 'base64'
|
5
8
|
|
6
9
|
module RubyCleverdome
|
7
10
|
class Client
|
8
|
-
def initialize(sso_endpoint,
|
11
|
+
def initialize(sso_endpoint, widgets_path)
|
12
|
+
@widgets_path = widgets_path
|
13
|
+
|
9
14
|
@sso_client = Savon.client(
|
10
15
|
endpoint: sso_endpoint,
|
11
16
|
namespace: 'urn:up-us:sso-service:service:v1',
|
12
|
-
|
17
|
+
proxy: 'http://127.0.0.1:8888',
|
13
18
|
# log_level: :debug
|
14
19
|
)
|
15
20
|
@widgets_client = Savon.client(
|
16
|
-
wsdl:
|
17
|
-
|
21
|
+
wsdl: widgets_path + '?wsdl',
|
22
|
+
proxy: 'http://127.0.0.1:8888',
|
18
23
|
element_form_default: :unqualified,
|
19
24
|
# log_level: :debug
|
20
25
|
)
|
@@ -38,7 +43,26 @@ module RubyCleverdome
|
|
38
43
|
response = @widgets_client.call(
|
39
44
|
method,
|
40
45
|
:attributes => { 'xmlns' => 'http://tempuri.org/' },
|
41
|
-
message: { sessionID: 'EE282ABB-7BC3-42D3-BE98-9F8CE4217A12' } .merge(locals)
|
46
|
+
message: { sessionID: 'EE282ABB-7BC3-42D3-BE98-9F8CE4217A12' } .merge(locals)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def upload_file(session_id, app_id, file_path)
|
51
|
+
data, headers = Multipart::Post.prepare_query(
|
52
|
+
"sessionID" => session_id,
|
53
|
+
"file" => File.open(file_path),
|
54
|
+
'applicationID' => app_id
|
55
|
+
)
|
56
|
+
|
57
|
+
response = @widgets_client.call(
|
58
|
+
:upload_file,
|
59
|
+
:attributes => {
|
60
|
+
'xmlns' => 'http://tempuri.org/'
|
61
|
+
},
|
62
|
+
message: {
|
63
|
+
inputStream: Base64.encode64(data)
|
64
|
+
})
|
65
|
+
response.body[:upload_file_response][:upload_file_result]
|
42
66
|
end
|
43
67
|
|
44
68
|
def create_request(provider, uid)
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Takes a hash of string and file parameters and returns a string of text
|
2
|
+
# formatted to be sent as a multipart form post.
|
3
|
+
#
|
4
|
+
# Author:: Cody Brimhall <mailto:brimhall@somuchwit.com>
|
5
|
+
# Created:: 22 Feb 2008
|
6
|
+
# License:: Distributed under the terms of the WTFPL (http://www.wtfpl.net/txt/copying/)
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'mime/types'
|
10
|
+
require 'cgi'
|
11
|
+
|
12
|
+
|
13
|
+
module Multipart
|
14
|
+
VERSION = "1.0.0"
|
15
|
+
|
16
|
+
# Formats a given hash as a multipart form post
|
17
|
+
# If a hash value responds to :string or :read messages, then it is
|
18
|
+
# interpreted as a file and processed accordingly; otherwise, it is assumed
|
19
|
+
# to be a string
|
20
|
+
class Post
|
21
|
+
# We have to pretend we're a web browser...
|
22
|
+
USERAGENT = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/523.10.6 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6"
|
23
|
+
BOUNDARY = "0123456789ABLEWASIEREISAWELBA9876543210"
|
24
|
+
CONTENT_TYPE = "multipart/form-data; boundary=#{ BOUNDARY }"
|
25
|
+
HEADER = { "Content-Type" => CONTENT_TYPE, "User-Agent" => USERAGENT }
|
26
|
+
|
27
|
+
def self.prepare_query(params)
|
28
|
+
fp = []
|
29
|
+
|
30
|
+
params.each do |k, v|
|
31
|
+
# Are we trying to make a file parameter?
|
32
|
+
if v.respond_to?(:path) and v.respond_to?(:read) then
|
33
|
+
fp.push(FileParam.new(k, v.path, v.read))
|
34
|
+
# We must be trying to make a regular parameter
|
35
|
+
else
|
36
|
+
fp.push(StringParam.new(k, v))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Assemble the request body using the special multipart format
|
41
|
+
query = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--"
|
42
|
+
return query, HEADER
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Formats a basic string key/value pair for inclusion with a multipart post
|
49
|
+
class StringParam
|
50
|
+
attr_accessor :k, :v
|
51
|
+
|
52
|
+
def initialize(k, v)
|
53
|
+
@k = k
|
54
|
+
@v = v
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_multipart
|
58
|
+
return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"\r\n\r\n#{v}\r\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Formats the contents of a file or string for inclusion with a multipart
|
63
|
+
# form post
|
64
|
+
class FileParam
|
65
|
+
attr_accessor :k, :filename, :content
|
66
|
+
|
67
|
+
def initialize(k, filename, content)
|
68
|
+
@k = k
|
69
|
+
@filename = filename
|
70
|
+
@content = content
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_multipart
|
74
|
+
# If we can tell the possible mime-type from the filename, use the
|
75
|
+
# first in the list; otherwise, use "application/octet-stream"
|
76
|
+
mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0]
|
77
|
+
return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"; filename=\"#{ filename }\"\r\n" +
|
78
|
+
"Content-Type: #{ mime_type.simplified }\r\n\r\n#{ content }\r\n"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-cleverdome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,38 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mime-types
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: base64
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
78
110
|
description: Ruby client to access CleverDome.
|
79
111
|
email: sanyo.gorbunov@gmail.com
|
80
112
|
executables: []
|
@@ -82,6 +114,7 @@ extensions: []
|
|
82
114
|
extra_rdoc_files: []
|
83
115
|
files:
|
84
116
|
- lib/ruby-cleverdome.rb
|
117
|
+
- lib/ruby-cleverdome/multipart.rb
|
85
118
|
homepage: https://github.com/SanyoGorbunov/ruby-cleverdome/
|
86
119
|
licenses: []
|
87
120
|
post_install_message:
|