Class: AlchemyLanguage::ActiveMethod::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy_language/active_method/base.rb

Direct Known Subclasses

HtmlService, TextService, UrlService

Constant Summary collapse

@@auth_url =
"#{AlchemyLanguage.base_url_request}/url/URLGetAuthors?apikey=#{AlchemyLanguage.secret_token}&url=www.ibm.com&outputMode=json"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#json_resObject

Returns the value of attribute json_res.



6
7
8
# File 'lib/alchemy_language/active_method/base.rb', line 6

def json_res
  @json_res
end

Class Method Details

.authenticate!Object



19
20
21
# File 'lib/alchemy_language/active_method/base.rb', line 19

def authenticate!
  return "secret key is not valid" unless authenticate_successfully?
end

.authenticate_successfully?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/alchemy_language/active_method/base.rb', line 23

def authenticate_successfully?
  @json_res = RestClient.get(@@auth_url)
  valid_api_key? ? true : false
end

.before_request(name) ⇒ Object



15
16
17
# File 'lib/alchemy_language/active_method/base.rb', line 15

def before_request(name)
  send name
end

.define_model(name) ⇒ Object



9
10
11
12
13
# File 'lib/alchemy_language/active_method/base.rb', line 9

def define_model(name)
  define_method(name) do |options = {}|
    eval("#{name.to_s.classify}").new(@path, @type, options)
  end
end

.json_parserObject



32
33
34
# File 'lib/alchemy_language/active_method/base.rb', line 32

def json_parser
  parse_in_json = JSON.parse(@json_res)
end

.valid_api_key?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/alchemy_language/active_method/base.rb', line 28

def valid_api_key?
  !json_parser.key?("statusInfo")
end