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.



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

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.


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

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.


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

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.


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

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

#authorsObject

Return a list of authors.



78
79
80
# File 'lib/jsb.rb', line 78

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

#create_journal(site, xml) ⇒ Object



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

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



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

def disable_journal(journal_id)
    parse(@api["/journals/#{journal_id}"].delete())
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



94
95
96
# File 'lib/jsb.rb', line 94

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

#journal_apps(journal_id) ⇒ Object



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

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.


86
87
88
# File 'lib/jsb.rb', line 86

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



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

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



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

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.



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

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

#statisticsObject

Return a group of methods of statistics.



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

def statistics
    @statistics
end