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.



156
157
158
# File 'lib/jsb.rb', line 156

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.


101
102
103
# File 'lib/jsb.rb', line 101

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) ⇒ Object

Return a list of articles from a issue.

Arguments:

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


81
82
83
# File 'lib/jsb.rb', line 81

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

#articles_by_section(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.


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

def articles_by_section(journal_id, issue_id, section_id)
    parse(@api["/journals/#{journal_id}/issues/#{issue_id}/sections/#{section_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.


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

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

#authorsObject

Return a list of authors.



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

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

#create_journal(site, xml) ⇒ Object



134
135
136
# File 'lib/jsb.rb', line 134

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



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

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

#issue(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.


63
64
65
# File 'lib/jsb.rb', line 63

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

#issues(journal_id) ⇒ Object

Return a list of issue from a journal.

Arguments:

journal_id: (Integer) id of journal.


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



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

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

#journal_apps(journal_id) ⇒ Object



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

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.


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

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



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

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



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

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.



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

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

#sections(journal_id, issue_id) ⇒ Object

Return a list of sections from a issue.

Arguments:

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


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

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

#statisticsObject

Return a group of methods of statistics.



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

def statistics
    @statistics
end