Class: GunsruAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/gunsru_api.rb

Overview

This class allows to access forum.guns.ru via JSON API

every instance method returns pair (HTTPResponse.code, Hash)

Instance Method Summary collapse

Constructor Details

#initialize(base_uri = "forum.guns.ru", api_uri = "/api/1.0/") ⇒ GunsruAPI

Creates new JSON API accessor



14
15
16
17
18
19
20
21
22
# File 'lib/gunsru_api.rb', line 14

def initialize(base_uri = "forum.guns.ru", api_uri = "/api/1.0/")
    @base_uri = base_uri
    @api_uri = api_uri
    #@logger = Logger.new(STDOUT)
    #@logger.formatter = proc do |sev, date, progname, msg|
        #"#{msg}\n"
    #end
    @etags = {}
end

Instance Method Details

#addMessageToTopicObject



149
150
151
152
# File 'lib/gunsru_api.rb', line 149

def addMessageToTopic()
    return -1, {}
    getResponse
end

#addTopicToFavouritesObject



141
142
143
144
# File 'lib/gunsru_api.rb', line 141

def addTopicToFavourites()
    return -1, {}
    getResponse
end

#getActiveTopics(from = 0, to = 20) ⇒ Object

Arguments: from, to Cacheable: yes Returns: hash

{
  timestamp: <unixtime>,
  topics: [ {
    type: "topic",
    title: <string>,
    id: <integer>,
    modificationTime: <unixtime>,
    postCount: <integer>,
    author: <string>,
    lastPost: <string> (author)
}]}


109
110
111
# File 'lib/gunsru_api.rb', line 109

def getActiveTopics(from=0, to=20)
    getResponse('from', from, 'to', to)
end

#getAllCategoriesObject

Arguments: none Cacheable: yes Returns: hash

{
  timestamp: <unixtime>,
  categories: [ {
    type: "category",
    title: <string>,
    id: <integer>,
    sections: [ {
      type: <string>,
      title: <string>,
      id: <integer>,
      modificationTime: <unixtime>,
      categoryId: <integer>
}]}]}


66
67
68
# File 'lib/gunsru_api.rb', line 66

def getAllCategories()
    getResponse()
end

#getConversationByIdObject



186
187
188
189
# File 'lib/gunsru_api.rb', line 186

def getConversationById()
    return -1, {}
    getResponse
end

#getConversationsObject



182
183
184
185
# File 'lib/gunsru_api.rb', line 182

def getConversations()
    return -1, {}
    getResponse
end

#getFavoritesSectionsObject

favorite sections manipulation



200
201
202
203
# File 'lib/gunsru_api.rb', line 200

def getFavoritesSections()
    return -1, {}
    getResponse
end

#getFavoriteTopicsObject



204
205
206
207
# File 'lib/gunsru_api.rb', line 204

def getFavoriteTopics()
    return -1, {}
    getResponse
end

#getFullMessageByIdObject



190
191
192
193
# File 'lib/gunsru_api.rb', line 190

def getFullMessageById()
    return -1, {}
    getResponse
end

#getLastTopicsObject

news & last topics



168
169
170
171
# File 'lib/gunsru_api.rb', line 168

def getLastTopics()
    return -1, {}
    getResponse
end

#getLinkedSectionsById(*args) ⇒ Object



137
138
139
140
# File 'lib/gunsru_api.rb', line 137

def getLinkedSectionsById(*args)
    return -1, {}
    getResponse
end

#getLinkedTopicsByIdObject



145
146
147
148
# File 'lib/gunsru_api.rb', line 145

def getLinkedTopicsById()
    return -1, {}
    getResponse
end

#getNewMessageCountObject



194
195
196
197
# File 'lib/gunsru_api.rb', line 194

def getNewMessageCount()
    return -1, {}
    getResponse
end

#getNewsObject



172
173
174
175
# File 'lib/gunsru_api.rb', line 172

def getNews()
    return -1, {}
    getResponse
end

#getPostByIdObject



161
162
163
164
# File 'lib/gunsru_api.rb', line 161

def getPostById()
    return -1, {}
    getResponse
end

#getPostsByTopicId(id, direction = 1, count = 1024) ⇒ Object

Arguments: id, direction, count. Optional: number, start_msg_id Cacheable: yes Returns: hash

{
  timestamp: <unixtime>,
  topic_id: <integer>,
  messages: [ {
    type: "post",
    body: <string>,
    id: <integer>,
    element_number: <integer>,
    createTime: <unixtime>,
    author: { [
      nickname: <string>,
      id: <integer>,
      userpic: [ { ... }],
    ]}
}]}


133
134
135
# File 'lib/gunsru_api.rb', line 133

def getPostsByTopicId(id, direction=1, count=1024)
    getResponse('id', id, 'direction', direction, 'count', count)
end

#getSectionByIdObject



153
154
155
156
# File 'lib/gunsru_api.rb', line 153

def getSectionById()
    return -1, {}
    getResponse
end

#getTopicByIdObject



157
158
159
160
# File 'lib/gunsru_api.rb', line 157

def getTopicById()
    return -1, {}
    getResponse
end

#getTopicsBySectionId(id, from = 0, to = 20) ⇒ Object

Arguments: id, from, to Cacheable: yes Returns: hash

{
  timestamp: <unixtime>,
  section_id: <unixtime>,
  topics: [ {
    type: "topic",
    topic_type: <string>,
    title: <string>,
    id: <integer>,
    element_number: <integer>,
    modificationTime: <unixtime>,
    postCount: <integer>,
    author: <string>,
    lastPost: <string> (author)
}]}


89
90
91
# File 'lib/gunsru_api.rb', line 89

def getTopicsBySectionId(id, from=0, to=20)
    getResponse('id', id, 'from', from, 'to', to)
end

#getUserProfileByIdObject

personal messages



178
179
180
181
# File 'lib/gunsru_api.rb', line 178

def getUserProfileById()
    return -1, {}
    getResponse
end

#logoutObject



221
222
223
224
# File 'lib/gunsru_api.rb', line 221

def logout()
    return -1, {}
    getResponse
end

#registerIosDeviceObject

push notifications



213
214
215
216
# File 'lib/gunsru_api.rb', line 213

def registerIosDevice()
    return -1, {}
    getResponse
end

#removeTopicFromFavouritesObject



208
209
210
211
# File 'lib/gunsru_api.rb', line 208

def removeTopicFromFavourites()
    return -1, {}
    getResponse
end

#unRegisterIosDeviceObject



217
218
219
220
# File 'lib/gunsru_api.rb', line 217

def unRegisterIosDevice()
    return -1, {}
    getResponse
end