Class: Iknow::List

Inherits:
Base
  • Object
show all
Defined in:
lib/iknow/model/list.rb

Overview

“iknow”: true,

"description": "hogehoge",
"translation_language": "ja",
"dictation": true,
"icon": "http://www.iknow.co.jp/assets/courses/m4.jpg",
"brainspeed": true,
"language": "en",
"item_count": 117,
"author_id": "Cerego",
"user_count": 45056,
"author": "Team iKnow!",
"title": "\u65c5\u306b\u51fa\u3088\u3046\uff01\uff08\u51fa\u56fd\uff06\u8857\u3092\u6b69\u304f\uff09",
"id": 708,
"author_url": "http://www.iknow.co.jp/user/Cerego"

Defined Under Namespace

Classes: Application

Constant Summary collapse

ATTRIBUTES =
[:id, :title, :description, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed,
:language, :translation_language, :list_type, :transcript, :embed,
:tags, :media_entry, :author, :author_id, :author_url, :attribution_license_id,
:items, :sentences]
READONLY_ATTRIBUTES =
[:id, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attributes, #attributes, deserialize, #deserialize

Constructor Details

#initialize(params = {}) ⇒ List

Returns a new instance of List.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/iknow/model/list.rb', line 62

def initialize(params = {})
  @id          = (params[:id].to_i rescue nil)
  @title       = params[:title]
  @description = params[:description]
  @icon        = params[:icon]
  @item_count  = (params[:item_count].to_i rescue nil)
  @user_count  = (params[:user_count].to_i rescue nil)
  @language    = params[:language]
  @translation_language = params[:translation_language]
  if @list_id and @translation_language
    common_settings = {:list_id => @id, :lang => @translation_language}
    @iknow      = Application.new(common_settings.merge(:application => 'iknow'))      if params[:iknow]
    @dictation  = Application.new(common_settings.merge(:application => 'dictation'))  if params[:dictation]
    @brainspeed = Application.new(common_settings.merge(:application => 'brainspeed')) if params[:brainspeed]
  end
  @author      = params[:author]      # display_name or username
  @author_id   = params[:author_id]   # username
  @author_url  = params[:author_url]
  @list_type   = params[:list_type]   # for list creation
  @transcript  = params[:transcript]  # for list creation
  @embed       = params[:embed]       # for list creation
  @tags        = params[:tags]        # for list creation
  @media_entry = params[:media_entry] # for list creation
  @attribution_license_id = params[:attribution_license_id] # for list creation
  @items     = self.deserialize(params[:items],     :as => Iknow::Item)
  @sentences = self.deserialize(params[:sentences], :as => Iknow::Sentence)
end

Class Method Details

.create(iknow_auth, params = {}) ⇒ Object



54
55
56
# File 'lib/iknow/model/list.rb', line 54

def self.create(iknow_auth, params = {})
  self.new(params).save(iknow_auth)
end

.delete(list_id) ⇒ Object



58
59
60
# File 'lib/iknow/model/list.rb', line 58

def self.delete(list_id)
  self.find(list_id).delete
end

.find(list_id, params = {}) ⇒ Object



42
43
44
45
46
# File 'lib/iknow/model/list.rb', line 42

def self.find(list_id, params = {})
  params[:id] = list_id
  hash = Iknow::RestClient::List.find(params)
  self.deserialize(hash)
end

.matching(keyword, params = {}) ⇒ Object



48
49
50
51
52
# File 'lib/iknow/model/list.rb', line 48

def self.matching(keyword, params = {})
  params[:keyword] = keyword
  hash = Iknow::RestClient::List.matching(params)
  self.deserialize(hash) || []
end

.recent(params = {}) ⇒ Object



37
38
39
40
# File 'lib/iknow/model/list.rb', line 37

def self.recent(params = {})
  hash = Iknow::RestClient::List.recent(params)
  self.deserialize(hash) || []
end

Instance Method Details

#add_item(iknow_auth, item) ⇒ Object



114
115
116
# File 'lib/iknow/model/list.rb', line 114

def add_item(iknow_auth, item)
  Iknow::RestClient::List.add_item(iknow_auth, {:list_id => self.id, :id => item.id})
end

#delete(iknow_auth) ⇒ Object Also known as: destroy



109
110
111
# File 'lib/iknow/model/list.rb', line 109

def delete(iknow_auth)
  Iknow::RestClient::List.delete(iknow_auth, {:id => self.id})
end

#delete_item(iknow_auth, item) ⇒ Object



118
119
120
# File 'lib/iknow/model/list.rb', line 118

def delete_item(iknow_auth, item)
  Iknow::RestClient::List.delete_item(iknow_auth, {:list_id => self.id, :id => item.id})
end

#items(params = {}) ⇒ Object



90
91
92
93
# File 'lib/iknow/model/list.rb', line 90

def items(params = {})
  hash = Iknow::RestClient::List.items(params.merge(:id => self.id))
  self.deserialize(hash, :as => Iknow::Item) || []
end

#save(iknow_auth) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/iknow/model/list.rb', line 100

def save(iknow_auth)
  begin
    list_id = Iknow::RestClient::List.create(iknow_auth, self.to_post_data)
  rescue
    return false
  end
  Iknow::List.find(list_id)
end

#sentences(params = {}) ⇒ Object



95
96
97
98
# File 'lib/iknow/model/list.rb', line 95

def sentences(params = {})
  hash = Iknow::RestClient::List.sentences(params.merge(:id => self.id))
  self.deserialize(hash, :as => Iknow::Sentence) || []
end