-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring and add pure_ruby example
- Loading branch information
nov
committed
Oct 16, 2008
1 parent
f4dc241
commit 402a162
Showing
10 changed files
with
161 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
*.gem | ||
*.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'rubygems' | ||
require 'iknow' | ||
|
||
Iknow::Config.init do |conf| | ||
conf.api_key = "" # Set your iKnow! API key, here. | ||
conf.host = "api.iknow.co.jp" | ||
end | ||
|
||
please_get_api_key =<<EOS | ||
This example needs your own iKnow! API key. | ||
(for only Iknow::Item.extract example) | ||
You can get iKnow! API key at iKnow! Developers. | ||
iKnow! Developers (http://developer.iknow.co.jp/) | ||
Thanks! | ||
EOS | ||
|
||
raise ArgumentError.new(please_get_api_key) if Iknow::Config.instance.api_key == '' | ||
|
||
## User API | ||
@user = Iknow::User.find('matake') | ||
@user.items | ||
@user.lists | ||
@user.friends | ||
@user.study_results | ||
@matchied_users = Iknow::User.matching('matake') | ||
|
||
# ## List API | ||
@recent_lists = Iknow::List.recent | ||
@matchied_lists = Iknow::List.matching("遺伝的アルゴリズム") | ||
@ga_list.first.items | ||
@ga_list.first.sentences | ||
|
||
# ## Item API | ||
@recent_items = Iknow::Item.recent | ||
@matchied_items = Iknow::Item.matching('record') | ||
@items = Iknow::Item.extract("sometimes, often, electrical") | ||
@items.first.sentences | ||
|
||
## Sentence API | ||
@recent_sentences = Iknow::Sentence.recent | ||
@matchied_sentences = Iknow::Sentence.matching('record') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
class Iknow::Base | ||
# TODO: define self.attributes | ||
def self.attributes; self::ATTRIBUTES end | ||
def attributes; self.class.attributes end | ||
|
||
def self.deserialize(response, params = {}) | ||
klass = params[:as] ? params[:as] : self | ||
response.is_a?(Array) ? response.inject([]) { |results, params| results << klass.new(params) } : klass.new(response) | ||
end | ||
def deserialize(response, params = {}) | ||
self.class.deserialize(response, params) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.