Class: Inbox::Namespace
Constant Summary
collapse
- OBJECTS_TABLE =
{
"account" => Inbox::Account,
"calendar" => Inbox::Calendar,
"draft" => Inbox::Draft,
"thread" => Inbox::Thread,
"contact" => Inbox::Contact,
"event" => Inbox::Event,
"file" => Inbox::File,
"message" => Inbox::Message,
"namespace" => Inbox::Namespace,
"tag" => Inbox::Tag,
}
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #as_json, #destroy, #inflate, #initialize, #save!, #update, #url
#time_attr_accessor
Methods included from Parameters
included, #parameters
Class Method Details
.collection_name ⇒ Object
26
27
28
|
# File 'lib/namespace.rb', line 26
def self.collection_name
"n"
end
|
Instance Method Details
#deltas(cursor, exclude_types = []) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/namespace.rb', line 90
def deltas(cursor, exclude_types=[])
raise 'Please provide a block for receiving the delta objects' if !block_given?
exclude_string = ""
if exclude_types.any?
exclude_string = "&exclude_types="
exclude_types.each do |value|
count = 0
if OBJECTS_TABLE.has_value?(value)
param_name = OBJECTS_TABLE.key(value)
exclude_string += "#{param_name},"
end
end
end
exclude_string = exclude_string[0..-2]
loop do
path = @_api.url_for_path("/n/#{@namespace_id}/delta?cursor=#{cursor}#{exclude_string}")
json = nil
RestClient.get(path) do |response,request,result|
json = Inbox.interpret_response(result, response, {:expected_class => Object})
end
start_cursor = json["cursor_start"]
end_cursor = json["cursor_end"]
json["deltas"].each do |delta|
cls = OBJECTS_TABLE[delta['object']]
obj = cls.new(@_api, @namespace_id)
case delta["event"]
when 'create', 'modify'
obj.inflate(delta['attributes'])
obj.cursor = delta["cursor"]
yield delta["event"], obj
when 'delete'
obj.id = delta["id"]
obj.cursor = delta["cursor"]
yield delta["event"], obj
end
end
break if start_cursor == end_cursor
cursor = end_cursor
end
end
|
#get_cursor(timestamp) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/namespace.rb', line 62
def get_cursor(timestamp)
path = @_api.url_for_path("/n/#{@namespace_id}/delta/generate_cursor")
data = { :start => timestamp }
cursor = nil
RestClient.post(path, data.to_json, :content_type => :json) do |response,request,result|
json = Inbox.interpret_response(result, response, {:expected_class => Object})
cursor = json["cursor"]
end
cursor
end
|