Class: JSB

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

Overview

Client to connect on Definity Journal Service Bus (JSB) Server. See more in jsb.definitysolutions.com

Defined Under Namespace

Classes: Apps, Statistics

Constant Summary collapse

API_URL =

URL for API

'http://jsb.definitysolutions.com/api/1.0'

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ JSB

initialize with api_key.

Arguments:

api_key: (String) is a code generate by application hosted on JSB server.


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

def initialize(api_key)
    @api_key = api_key
    @headers = { :"JSB-Api-Key" => api_key }
    @statistics = JSB::Statistics.new(self)
    @apps = JSB::Apps.new(self)

    @api = RestClient::Resource.new(API_URL, :content_type => "application/json", :headers => @headers)
end

Instance Method Details

#apiObject

Return a API REST client resource.



147
148
149
# File 'lib/jsb.rb', line 147

def api
    @api
end

#article(journal_id, issue_id, article_id) ⇒ Object

Return a specific article.

Arguments:

journal_id: (Integer) id of journal.
issue_id: (Integer) id of issue.
article_id: (Integer) id of article.


92
93
94
# File 'lib/jsb.rb', line 92

def article(journal_id, issue_id, article_id)
    parse(@api["/journals/#{journal_id}/issues/#{issue_id}/articles/#{article_id}"].get(:accept => :json))
end

#articles(journal_id, issue_id, section_id) ⇒ Object

Return a list of articles by section from a issue.

Arguments:

journal_id: (Integer) id of journal.
issue_id: (Integer) id of issue.
section_id: (Integer) id of section.


72
73
74
# File 'lib/jsb.rb', line 72

def articles(journal_id, issue_id)
    parse(@api["/journals/#{journal_id}/issues/#{issue_id}/articles"].get(:accept => :json))
end

#author_articles(author_id) ⇒ Object

Return a list of articles from author.

Arguments:

author_id: (Integer) id of author.


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

def author_articles(author_id)
    parse(@api["/authors/#{author_id}/articles"].get(:accept => :json))
end

#authorsObject

Return a list of authors.



97
98
99
# File 'lib/jsb.rb', line 97

def authors
    parse(@api["/authors"].get(:accept => :json))
end

#create_journal(site, xml) ⇒ Object



125
126
127
# File 'lib/jsb.rb', line 125

def create_journal(site, xml)
    parse(@api["/journals"].post(:journal => {:site => site, :xml => xml}, :accept => :json, :timeout => 90000000, :open_timeout => 90000000))
end

#disable_journal(journal_id) ⇒ Object



129
130
131
# File 'lib/jsb.rb', line 129

def disable_journal(journal_id)
    parse(@api["/journals/#{journal_id}"].delete())
end

#issues(journal_id, issue_id) ⇒ Object

Return a specif issue from a journal.

Arguments:

journal_id: (Integer) id of journal.
issue_id: (Integer) id of issue.


54
55
56
# File 'lib/jsb.rb', line 54

def issues(journal_id)
    parse(@api["/journals/#{journal_id}/issues"].get(:accept => :json))
end

#journal(journal_id) ⇒ Object

Return a specific journal.

Arguments:

journal_id: (Integer) id of journal.


37
38
39
# File 'lib/jsb.rb', line 37

def journal(journal_id)
    parse(@api["/journals/#{journal_id}"].get(:accept => :json))
end

#journal_app(journal_id, app_id) ⇒ Object



113
114
115
# File 'lib/jsb.rb', line 113

def journal_app(journal_id, app_id)
    parse(@api["/journals/#{journal_id}/apps/#{app_id}"].get(:accept => :json))
end

#journal_apps(journal_id) ⇒ Object



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

def journal_apps(journal_id)
    parse(@api["/journals/#{journal_id}/apps"].get(:accept => :json))
end

#journal_authors(journal_id) ⇒ Object

Return a list of authors from a journal.

Arguments:

journal_id: (Integer) id of journal.


105
106
107
# File 'lib/jsb.rb', line 105

def journal_authors(journal_id)
    parse(@api["/journals/#{journal_id}/authors"].get(:accept => :json))
end

#journal_exists?(site) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/jsb.rb', line 29

def journal_exists?(site)
    @api["/journals/exists"].get(:params => {:site => site}, :accept => :json)
end

#journal_install_app(journal_id, app_id, expires_at) ⇒ Object



117
118
119
# File 'lib/jsb.rb', line 117

def journal_install_app(journal_id, app_id, expires_at)
    parse(@api["/journals/#{journal_id}/apps/#{app_id}"].put(:expires_at => expires_at, :accept => :json))
end

#journal_sync(journal_id, force = false) ⇒ Object

Syncronize journal with OJS.

Arguments:

journal_id: (Integer) id of journal.
force: (String) if force is true, will force update all data.


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

def journal_sync(journal_id, force = false)
    parse(@api["/journals/#{journal_id}/sync"].get(:params => {:force => force}, :accept => :json, :timeout => 90000000, :open_timeout => 90000000))
end

#journal_uninstall_app(journal_id, app_id) ⇒ Object



121
122
123
# File 'lib/jsb.rb', line 121

def journal_uninstall_app(journal_id, app_id)
    parse(@api["/journals/#{journal_id}/apps/#{app_id}"].delete(:accept => :json))
end

#journalsObject

Return a list of journals.



25
26
27
# File 'lib/jsb.rb', line 25

def journals
    parse(@api["/journals"].get(:accept => :json))
end

#parse(obj) ⇒ Object

Parse JSON to hash.



152
153
154
# File 'lib/jsb.rb', line 152

def parse(obj)
    JSON.parse(obj)
end

#statisticsObject

Return a group of methods of statistics.



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

def statistics
    @statistics
end