kateglo 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +16 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kateglo.gemspec +29 -0
- data/lib/kateglo.rb +56 -0
- data/lib/kateglo/kata.rb +64 -0
- data/lib/kateglo/version.rb +3 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a6b0b299b0a9c9451c9edf144c566decea377eb
|
4
|
+
data.tar.gz: aac94c03dea9f0eac76e540809f261be44b50405
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 323101278e298ae46e146854a654f5f2e227db7cb887c37bf74105f6caf4239a0de227a6fe1d816dbfef9394227e6542fd9e925160e8034f2b79aeac0fe8bf84
|
7
|
+
data.tar.gz: eb793beb768765384009db7b7c07a878d4b4008597e6082637bb452c678d216ce23f73f609d0719c7925a107e2680320c691b57bd40e5e645e06efa7eede5b7b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
|
6
|
+
# To use in development
|
7
|
+
group :development do
|
8
|
+
gem 'guard'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'pry', require: true
|
11
|
+
|
12
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
13
|
+
gem 'growl'
|
14
|
+
gem 'rb-fsevent', require: false
|
15
|
+
end
|
16
|
+
end
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adrian Setyadi, Adinda Praditya
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Kateglo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'kateglo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install kateglo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kateglo"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/kateglo.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kateglo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "kateglo"
|
8
|
+
s.version = Kateglo::VERSION
|
9
|
+
s.authors = ["Adrian Setyadi", "Adinda Praditya"]
|
10
|
+
s.email = ["a.styd@yahoo.com", "apraditya@gmail.com"]
|
11
|
+
s.description = %q{The unofficial Ruby library for accessing Kateglo API, an online dictionary, thesaurus and glossarium for bahasa Indonesia}
|
12
|
+
s.summary = %q{Kateglo Ruby gem}
|
13
|
+
s.homepage = "https://github.com/styd/kateglo"
|
14
|
+
|
15
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
s.bindir = "exe"
|
19
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'addressable'
|
27
|
+
s.add_runtime_dependency 'multi_json'
|
28
|
+
|
29
|
+
end
|
data/lib/kateglo.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'kateglo/version'
|
2
|
+
require 'kateglo/kata'
|
3
|
+
require 'net/http'
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'multi_json'
|
6
|
+
|
7
|
+
module Kateglo
|
8
|
+
class RequestError < StandardError; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
BASE_URL = "http://kateglo.com/api.php"
|
12
|
+
BASE_PARAMS = { format: 'json' }
|
13
|
+
|
14
|
+
def lookup(lemma)
|
15
|
+
@lemma = lemma
|
16
|
+
if @lemma =~ /\s/
|
17
|
+
@lemma.split(/\s+/).map do |l|
|
18
|
+
begin
|
19
|
+
lookup(l)
|
20
|
+
rescue MultiJson::LoadError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
else
|
24
|
+
@uri = Addressable::URI.parse BASE_URL
|
25
|
+
@uri.query_values = BASE_PARAMS.merge(phrase: @lemma)
|
26
|
+
response = Net::HTTP.get_response(@uri)
|
27
|
+
|
28
|
+
unless response.kind_of? Net::HTTPSuccess
|
29
|
+
raise Kateglo::RequestError, "HTTP Response: #{response.code} #{response.message}"
|
30
|
+
end
|
31
|
+
parse_response(response.body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
private
|
37
|
+
def parse_response(response)
|
38
|
+
begin
|
39
|
+
parsed_json = MultiJson.load response
|
40
|
+
Kata.new parsed_json
|
41
|
+
rescue MultiJson::LoadError
|
42
|
+
LemmaNotFound.new("No entry found for '#{@lemma}'", @uri)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class LemmaNotFound
|
48
|
+
attr_reader :message, :uri
|
49
|
+
|
50
|
+
def initialize(message, uri)
|
51
|
+
@message = message
|
52
|
+
@uri = uri
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/lib/kateglo/kata.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Kateglo
|
2
|
+
class BaseKata
|
3
|
+
def initialize(hash)
|
4
|
+
assign_attribute_names hash
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
private
|
9
|
+
def assign_attribute_names(hash_response)
|
10
|
+
attributes = hash_response.keys
|
11
|
+
self.class.class_eval { attr_reader *attributes }
|
12
|
+
attributes.each do |attr_name|
|
13
|
+
attribute_value = hash_response[attr_name]
|
14
|
+
if attribute_value
|
15
|
+
if attribute_value.is_a?(Array)
|
16
|
+
assign_array_attributes(attr_name, attribute_value)
|
17
|
+
else
|
18
|
+
instance_variable_set("@#{attr_name}", attribute_value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def assign_array_attributes(attr_name, hash_array)
|
25
|
+
value = hash_array.map { |hash_attr| BaseKata.new(hash_attr) }
|
26
|
+
instance_variable_set("@#{attr_name}", value)
|
27
|
+
self.class.send :define_method, "has_#{attr_name}?" do
|
28
|
+
send(attr_name).any?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Kata < BaseKata
|
34
|
+
def initialize(hash)
|
35
|
+
assign_attribute_names hash['kateglo']
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
private
|
40
|
+
def assign_attribute_names(hash_response)
|
41
|
+
super hash_response
|
42
|
+
assign_relations if relation.any?
|
43
|
+
end
|
44
|
+
|
45
|
+
def assign_relations
|
46
|
+
relation_hashes = relation.keys.map do |rel_type|
|
47
|
+
relation[rel_type] if relation[rel_type].is_a?(Hash)
|
48
|
+
end.compact
|
49
|
+
relation_hashes.each do |relation_hash|
|
50
|
+
if relation_hash['name']
|
51
|
+
method_name = relation_hash.delete('name').downcase.gsub(/\s/, '_')
|
52
|
+
self.class.send :define_method, method_name.to_sym do
|
53
|
+
relation_hash.values.map do |hash_attr|
|
54
|
+
(hash_attr.is_a?(Hash))? BaseKata.new(hash_attr) : hash_attr
|
55
|
+
end
|
56
|
+
end
|
57
|
+
self.class.send :define_method, "has_#{method_name}?" do
|
58
|
+
self.send(method_name).any?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kateglo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Setyadi
|
8
|
+
- Adinda Praditya
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: addressable
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: multi_json
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: The unofficial Ruby library for accessing Kateglo API, an online dictionary,
|
71
|
+
thesaurus and glossarium for bahasa Indonesia
|
72
|
+
email:
|
73
|
+
- a.styd@yahoo.com
|
74
|
+
- apraditya@gmail.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- Gemfile
|
81
|
+
- Guardfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- kateglo.gemspec
|
88
|
+
- lib/kateglo.rb
|
89
|
+
- lib/kateglo/kata.rb
|
90
|
+
- lib/kateglo/version.rb
|
91
|
+
homepage: https://github.com/styd/kateglo
|
92
|
+
licenses: []
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Kateglo Ruby gem
|
114
|
+
test_files: []
|