Class: NTimeLine::TimeLine

Inherits:
Base
  • Object
show all
Defined in:
lib/ntimeline/timeline.rb

Overview

TimeLine is a timeline data.

Instance Attribute Summary collapse

Attributes inherited from Base

#timeline_key, #updated

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bool_data, #initialize, int_data, #refresh, request, #request, request_with_key, #request_with_key, text_data, time_data, url_data

Constructor Details

This class inherits a constructor from NTimeLine::Base

Instance Attribute Details

#labelsObject (readonly)

Returns the value of attribute labels.



12
13
14
# File 'lib/ntimeline/timeline.rb', line 12

def labels
  @labels
end

#locked_forObject (readonly)

Returns the value of attribute locked_for.



12
13
14
# File 'lib/ntimeline/timeline.rb', line 12

def locked_for
  @locked_for
end

#opened_forObject (readonly)

Returns the value of attribute opened_for.



12
13
14
# File 'lib/ntimeline/timeline.rb', line 12

def opened_for
  @opened_for
end

Class Method Details

.create(params) ⇒ Object

Create new timeline.

params

See webservice.nifty.com/timeline/v1/timelines/create.htm.

  • :title (required)

  • :description (required)

  • :label_for_vaxis (required)

  • :vaxis_mode

  • :label

  • :time_scale

  • :initial_position

  • :category

  • :commentable

  • :open_level

  • :opened_for

  • :lock_level

  • :locked_for



90
91
92
93
94
95
96
97
98
99
# File 'lib/ntimeline/timeline.rb', line 90

def self.create(params)
  unless params.include?(:title)    &&
      params.include?(:description) &&
      params.include?(:label_for_vaxis)
    raise ArgumentError, <<-ERR
Required parameters(:title, :description, :label_for_vaxis) are missing.
    ERR
  end
  request_with_key("/timelines/create", params)
end

.delete(id, timeline_key, delete_articles = false) ⇒ Object

Delete a timeline. See webservice.nifty.com/timeline/v1/timelines/delete.htm for details.

id

timeline id

timeline_key

timeline API key

delete_articles

Delete all articles in the timeline if true.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ntimeline/timeline.rb', line 139

def self.delete(id, timeline_key, delete_articles=false)
  # before deleting the timeline, delete all articles of it
  if delete_articles
    pager = Article.search(:timeline_key => timeline_key,
                           :timeline_id => id)
    while pager do
      pager.articles.each do |article|
        article.delete
      end
      pager = pager.next
    end
  end

  # send
  request_with_key("/timelines/delete/#{id}",
                   {:timeline_key => timeline_key},
                   Succeeded)
end

.search(params) ⇒ Object

Search timelines.

params

See webservice.nifty.com/timeline/v1/timelines/search.htm.

  • :timeline_key

  • :owner (required if phrase is empty)

  • :phrase (required if owner is empty)

  • :hits

  • :order



57
58
59
# File 'lib/ntimeline/timeline.rb', line 57

def self.search(params)
  request("/timelines/search", params, TimeLinePager)
end

.search_by_owner(owner, params = {}) ⇒ Object

Search timelines by owner name.

owner

owner nickname

params

same as search



64
65
66
# File 'lib/ntimeline/timeline.rb', line 64

def self.search_by_owner(owner, params={})
  search(params.merge(:owner => owner))
end

.search_by_phrase(phrase, params = {}) ⇒ Object

Searches timelines by phrase.

phrase

query phrase

params

same as search



71
72
73
# File 'lib/ntimeline/timeline.rb', line 71

def self.search_by_phrase(phrase, params={})
  search(params.merge(:phrase => phrase))
end

.show(id, params = {}) ⇒ Object

Fetch a timeline by id.

id

timeline id

params

See webservice.nifty.com/timeline/v1/timelines/show.htm.

  • :timeline_key



46
47
48
# File 'lib/ntimeline/timeline.rb', line 46

def self.show(id, params={})
  request("/timelines/show/#{id}", params)
end

.update(id, params, target = self) ⇒ Object

Update a timeline.

id

timeline id

params

See webservice.nifty.com/timeline/v1/timelines/create.htm.

  • :timeline_key (required)

  • :title

  • :description

  • :label_for_vaxis

  • :vaxis_mode

  • :label

  • :time_scale

  • :initial_position

  • :category

  • :commentable

  • :open_level

  • :opened_for

  • :lock_level

  • :locked_for



118
119
120
121
# File 'lib/ntimeline/timeline.rb', line 118

def self.update(id, params, target=self)
  # request
  request_with_key("/timelines/update/#{id}", params, target)
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/ntimeline/timeline.rb', line 38

def ==(other)
  @id == other.id
end

#create_article(params = {}) ⇒ Object

Create a new aritcle.

params

Same as Article.create.



175
176
177
178
179
180
181
182
183
184
# File 'lib/ntimeline/timeline.rb', line 175

def create_article(params={})
  # merge
  unless params.has_key?(:timeline_key)
    params = params.merge(:timeline_key => @timeline_key)
  end
  params = params.merge(:timeline_id => @id)

  # send
  Article.create(params)
end

#delete(delete_articles = false) ⇒ Object

Delete the timeline.

delete_articles

Same as TimeLine.delete.



160
161
162
# File 'lib/ntimeline/timeline.rb', line 160

def delete(delete_articles=false)
  self.class.delete(@id, @timeline_key, delete_articles)
end

#init(doc) ⇒ Object

:nodoc:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ntimeline/timeline.rb', line 14

def init(doc) #:nodoc:
  elt = nil
  if doc.kind_of?(REXML::Document)
    unless elt = doc.root.elements["/response/result/timeline"]
      raise ArgumentError, doc
    end
  else
    elt = doc
  end
  super(elt)
  @opened_for = []
  if users = elt.elements["opened_for"].text
    @opened_for = users.split(" ")
  end
  @locked_for = []
  if users = elt.elements["locked_for"].text
    @locked_for = users.split(" ")
  end
  @labels = []
  elt.each_element("labels/label") do |label|
    @labels << label.text
  end
end

#search_articles(params = {}) ⇒ Object

Search articles in this timeline.

params

Same as Article.search.



166
167
168
169
170
171
# File 'lib/ntimeline/timeline.rb', line 166

def search_articles(params={})
  # merge
  params = params.merge(:timeline_id => @id, :timeline_key => @timeline_key)
  # search
  Article.search(params)
end

#update(params) ⇒ Object

Update the timeline.

params

Same as update.



125
126
127
128
129
130
131
132
# File 'lib/ntimeline/timeline.rb', line 125

def update(params)
  # merge key
  unless params.has_key? :timeline_key
    params = params.merge(:timeline_key => @timeline_key)
  end
  # update
  self.class.update(@id, params, self)
end