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, :square_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.



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
89
90
91
# File 'lib/iknow/model/list.rb', line 64

def initialize(params = {})
  @id          = (params[:id].to_i rescue nil)
  @title       = params[:title]
  @description = params[:description]
  @icon        = params[:icon]
  @square_icon = params[:square_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



56
57
58
# File 'lib/iknow/model/list.rb', line 56

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

.delete(list_id) ⇒ Object



60
61
62
# File 'lib/iknow/model/list.rb', line 60

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

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



44
45
46
47
48
# File 'lib/iknow/model/list.rb', line 44

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

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



50
51
52
53
54
# File 'lib/iknow/model/list.rb', line 50

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

.recent(params = {}) ⇒ Object



39
40
41
42
# File 'lib/iknow/model/list.rb', line 39

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

Instance Method Details

#add_item(iknow_auth, item) ⇒ Object



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

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



112
113
114
# File 'lib/iknow/model/list.rb', line 112

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

#delete_item(iknow_auth, item) ⇒ Object



121
122
123
# File 'lib/iknow/model/list.rb', line 121

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

#items(params = {}) ⇒ Object



93
94
95
96
# File 'lib/iknow/model/list.rb', line 93

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

#save(iknow_auth) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/iknow/model/list.rb', line 103

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



98
99
100
101
# File 'lib/iknow/model/list.rb', line 98

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