Class: DocodocoJp

Inherits:
Object
  • Object
show all
Defined in:
lib/docodoco_jp.rb,
lib/docodoco_jp/cli.rb,
lib/docodoco_jp/version.rb,
lib/docodoco_jp/api_key_invalid.rb,
lib/docodoco_jp/ipv4_validation_error.rb

Defined Under Namespace

Classes: ApiKeyInvalid, CLI, IPv4ValidationError

Constant Summary collapse

DEFAULT_API_HOST =
'api.docodoco.jp'
VERSION =
"1.0.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey1, apikey2, options = {}) ⇒ DocodocoJp

Returns a new instance of DocodocoJp.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/docodoco_jp.rb', line 42

def initialize(apikey1, apikey2, options ={})
  @apikey = [apikey1, apikey2]
  @user_valid = false
  @config = self.class.default_config
  @config = @config.merge({
    ssl: options[:ssl],
    faraday_log: options[:faraday_log],
    charset: options[:charset],
    response_type: options[:response_type]
  }) do |k, n, o|
    result = n
    result = o unless o.nil?

    result
  end
end

Instance Attribute Details

#apikeyObject (readonly)

Returns the value of attribute apikey.



18
19
20
# File 'lib/docodoco_jp.rb', line 18

def apikey
  @apikey
end

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/docodoco_jp.rb', line 19

def config
  @config
end

#user_validObject (readonly)

Returns the value of attribute user_valid.



20
21
22
# File 'lib/docodoco_jp.rb', line 20

def user_valid
  @user_valid
end

Class Method Details

.api_hostObject



27
28
29
30
# File 'lib/docodoco_jp.rb', line 27

def api_host
  @api_host = DEFAULT_API_HOST if @api_host.nil?
  return @api_host
end

.api_host=(host) ⇒ Object



23
24
25
# File 'lib/docodoco_jp.rb', line 23

def api_host=(host)
  @api_host = host
end

.default_configObject



32
33
34
35
36
37
38
39
# File 'lib/docodoco_jp.rb', line 32

def default_config
  return {
    ssl: true,
    faraday_log: false,
    charset: "utf_8",
    response_type: :hashie
  }
end

Instance Method Details

#check_userObject



67
68
69
70
71
72
73
74
# File 'lib/docodoco_jp.rb', line 67

def check_user()
  xmldoc = REXML::Document.new(check_user_api().body)
  status  = xmldoc.elements['/docodoco/user_status'].get_text.to_s.to_i
  message = xmldoc.elements['/docodoco/user_status_message'].get_text.to_s
  result = [200, 201].include?(status)
  @user_valid = true
  return result, {status: status, message: message}
end

#check_user!Object



76
77
78
79
80
# File 'lib/docodoco_jp.rb', line 76

def check_user!()
  result, json = check_user
  raise DocodocoJp::ApiKeyInvalid unless result
  return result, json
end

#search(ipadr = nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/docodoco_jp.rb', line 59

def search(ipadr = nil)
  result = hash_nomalize(JSON.parse(search_api(ipadr).body))
  if config[:response_type] == :hashie
    result = Hashie::Mash.new(result)
  end
  return result
end