Class: RubyCleverdome::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-cleverdome.rb

Instance Method Summary collapse

Constructor Details

#initialize(sso_endpoint, widgets_path) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby-cleverdome.rb', line 11

def initialize(sso_endpoint, widgets_path)
  @widgets_path = widgets_path

  @sso_client = Savon.client(
      endpoint: sso_endpoint,
      namespace: 'urn:up-us:sso-service:service:v1',
    # proxy: 'http://127.0.0.1:8888',

    # log_level: :debug

      )
  @widgets_client = Savon.client(
    wsdl: widgets_path + '?wsdl',
    # proxy: 'http://127.0.0.1:8888',

    element_form_default: :unqualified,
    # log_level: :debug

  )
end

Instance Method Details

#auth(provider, uid, private_key_file, certificate_file) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby-cleverdome.rb', line 28

def auth(provider, uid, private_key_file, certificate_file)
  req = create_request(provider, uid)

      req = sign_request(req, private_key_file, certificate_file)

      resp = saml_call(req)
      resp_doc = Nokogiri::XML::Document.parse(resp)
  resp_doc.remove_namespaces!
      check_resp(resp_doc)

      session_id = resp_doc.xpath('//Assertion//AttributeStatement//Attribute[@Name="SessionID"]//AttributeValue')[0].content
      session_id
end

#get_document_template(session_id, doc_guid) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ruby-cleverdome.rb', line 86

def get_document_template(session_id, doc_guid)
  resp_doc = widgets_call(
    :get_document_template,
    {
      'sessionID' => session_id,
      'documentGuid' => doc_guid
    }).doc

  check_body(resp_doc)

  return [Integer(resp_doc.xpath('//ReturnValue/ID')[0].content), resp_doc.xpath('//ReturnValue/Name')[0].content]
end

#get_document_type(session_id, doc_guid) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ruby-cleverdome.rb', line 118

def get_document_type(session_id, doc_guid)
  resp_doc = widgets_call(
    :get_document_type,
    {
      'sessionID' => session_id,
      'documentGuid' => doc_guid
    }).doc

  check_body(resp_doc)

  return [Integer(resp_doc.xpath('//ReturnValue/ID')[0].content), resp_doc.xpath('//ReturnValue/Name')[0].content]
end

#get_template_types(session_id, app_id, template_id) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ruby-cleverdome.rb', line 99

def get_template_types(session_id, app_id, template_id)
  resp_doc = widgets_call(
    :get_document_types,
    {
  'sessionID' => session_id,
      'templateID' => template_id,
      'applicationID' => app_id
    }).doc

  check_body(resp_doc)

  hash = resp_doc.xpath('//ReturnValue')[0]
    .element_children.each_with_object(Hash.new) do |e, h|
    h[Integer(e.at('ID').content)] = e.at('Name').content
  end

  hash
end

#get_templates(session_id, app_id) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ruby-cleverdome.rb', line 68

def get_templates(session_id, app_id)
  resp_doc = widgets_call(
    :get_document_templates,
    {
      'sessionID' => session_id,
      'applicationID' => app_id
    }).doc

  check_body(resp_doc)

  hash = resp_doc.xpath('//ReturnValue')[0]
    .element_children.each_with_object(Hash.new) do |e, h|
    h[Integer(e.at('ID').content)] = e.at('Name').content
  end

  hash
end

#set_document_template_type(session_id, doc_guid, template_id, type_id) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ruby-cleverdome.rb', line 131

def set_document_template_type(session_id, doc_guid, template_id, type_id)
  resp_doc = widgets_call(
    :set_document_template,
    {
  'sessionID' => session_id,
      'documentGuid' => doc_guid,
      'templateID' => template_id,
      'documentTypeID' => type_id
    }).doc

  check_body(resp_doc)
end

#upload_file(session_id, app_id, file_path) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby-cleverdome.rb', line 50

def upload_file(session_id, app_id, file_path)
  data, headers = Multipart::Post.prepare_query(
    "sessionID"   => session_id,
    "file"      => File.open(file_path),
    'applicationID' => app_id
    )

  response = @widgets_client.call(
    :upload_file,
    :attributes => {
      'xmlns' => 'http://tempuri.org/'
      },
    message: {
      inputStream: Base64.encode64(data)
      })
  response.body[:upload_file_response][:upload_file_result]
end

#widgets_call(method, locals) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/ruby-cleverdome.rb', line 42

def widgets_call(method, locals)
  response = @widgets_client.call(
method,
:attributes => { 'xmlns' => 'http://tempuri.org/' }, 
message: locals
)
end