Class: WeConnect::Authentication::IDKParser

Inherits:
Object
  • Object
show all
Defined in:
lib/weconnect/authorization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ IDKParser

Returns a new instance of IDKParser.



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/weconnect/authorization.rb', line 206

def initialize(html)
  doc = Nokogiri::HTML( html )
  # get script with IDK
  scripts = doc./'script:contains("_IDK")'
  # extract json part by greedy match till last '}'
  m = scripts.text.gsub("\n",'').gsub(/([\w]+):/, '"\1":').match('({.*})')
  @idk = {}
  if m.size > 1
    # load with yam due to single quotes
    @idk = YAML.load(m[1])
    raise IncompatibleAPIError.new( "_IDK.templateModel not found #{@idk}" ) unless @idk['templateModel']
  else
    raise IncompatibleAPIError.new( "_IDK not found" )
  end
  # r = self.__get_url(upr.scheme+'://'+upr.netloc+form_url.replace(idk['templateModel']['identifierUrl'],idk['templateModel']['postAction']), post=post)
  @template_model = @idk['templateModel']
  @post_action = @template_model['postAction']
  @identifier = @template_model['identifierUrl']
  @error = @template_model['error']
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



205
206
207
# File 'lib/weconnect/authorization.rb', line 205

def error
  @error
end

#identifierObject (readonly)

Returns the value of attribute identifier.



205
206
207
# File 'lib/weconnect/authorization.rb', line 205

def identifier
  @identifier
end

#idkObject (readonly)

Returns the value of attribute idk.



205
206
207
# File 'lib/weconnect/authorization.rb', line 205

def idk
  @idk
end

#post_actionObject (readonly)

Returns the value of attribute post_action.



205
206
207
# File 'lib/weconnect/authorization.rb', line 205

def post_action
  @post_action
end

#template_modelObject (readonly)

Returns the value of attribute template_model.



205
206
207
# File 'lib/weconnect/authorization.rb', line 205

def template_model
  @template_model
end

Instance Method Details

#post_action_uri(base_uri) ⇒ Object



227
228
229
# File 'lib/weconnect/authorization.rb', line 227

def post_action_uri(base_uri)
  base_uri.to_s.gsub(@identifier,@post_action)
end