jsb_client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/jsb_client/ruby/v1/lib/jsb.rb +151 -0
  3. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05160b9a8640c2687fe4b027940c9258dc5ccb4b
4
+ data.tar.gz: aa1668409ed1e21cdf7d3e5145cf1ba556e9127e
5
+ SHA512:
6
+ metadata.gz: 128a0fcc434e42d258e199d711beaf487ebaaadaf2aeba47f3f0fd96392e053c135845e75065610080a54736712df59dd91a63c5b2f7bb10d6410cbc8a6c1f87
7
+ data.tar.gz: 2943cd46812e1b94e2bf7b872bcd2aa88593f0119640b90ec7ecfe2352d9b7dbb7e4d5eaee30f94a6897a7a53202d1d66eb95afb0285b24383a1b75dd8e851b5
@@ -0,0 +1,151 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ # Client to connect on Definity Journal Service Bus (JSB) Server.
5
+ # See more in http://jsb.definitysolutions.com
6
+ class JSB
7
+
8
+ # URL for API
9
+ API_URL = 'http://jsb.definitysolutions.com/api/1.0'
10
+
11
+ # initialize with api_key.
12
+ #
13
+ # Arguments:
14
+ # api_key: (String) is a code generate by application hosted on JSB server.
15
+ def initialize(api_key)
16
+ @api_key = api_key
17
+ @headers = { :"JSB-Api-Key" => api_key }
18
+ @statistics = JSB::Statistics.new(self)
19
+
20
+ @api = RestClient::Resource.new(API_URL, :content_type => "application/json", :headers => @headers)
21
+ end
22
+
23
+ # Return a list of journals.
24
+ def journals
25
+ parse(@api["/journals"].get(:accept => :json))
26
+ end
27
+
28
+ # Return a specific journal.
29
+ #
30
+ # Arguments:
31
+ # journal_id: (Integer) id of journal.
32
+ def journal(journal_id)
33
+ parse(@api["/journals/#{journal_id}"].get(:accept => :json))
34
+ end
35
+
36
+ # Syncronize journal with OJS.
37
+ #
38
+ # Arguments:
39
+ # journal_id: (Integer) id of journal.
40
+ # force: (String) if force is true, will force update all data.
41
+ def journal_sync(journal_id, force = false)
42
+ parse(@api["/journals/#{journal_id}/sync"].get(:force => force, :accept => :json))
43
+ end
44
+
45
+ # Return a list of issue from a journal.
46
+ #
47
+ # Arguments:
48
+ # journal_id: (Integer) id of journal.
49
+ def issues(journal_id)
50
+ parse(@api["/journals/#{journal_id}/issues"].get(:accept => :json))
51
+ end
52
+
53
+ # Return a list of articles from a issue.
54
+ #
55
+ # Arguments:
56
+ # journal_id: (Integer) id of journal.
57
+ # issue_id: (Integer) id of issue.
58
+ def articles(journal_id, issue_id)
59
+ parse(@api["/journals/#{journal_id}/issues/#{issue_id}/articles"].get(:accept => :json))
60
+ end
61
+
62
+ # Return a specific article.
63
+ #
64
+ # Arguments:
65
+ # journal_id: (Integer) id of journal.
66
+ # issue_id: (Integer) id of issue.
67
+ # article_id: (Integer) id of article.
68
+ def article(journal_id, issue_id, article_id)
69
+ parse(@api["/journals/#{journal_id}/issues/#{issue_id}/articles/#{article_id}"].get(:accept => :json))
70
+ end
71
+
72
+ # Return a list of authors.
73
+ def authors
74
+ parse(@api["/authors"].get(:accept => :json))
75
+ end
76
+
77
+ # Return a list of authors from a journal.
78
+ #
79
+ # Arguments:
80
+ # journal_id: (Integer) id of journal.
81
+ def journal_authors(journal_id)
82
+ parse(@api["/journals/#{journal_id}/authors"].get(:accept => :json))
83
+ end
84
+
85
+ # Return a list of articles from author.
86
+ #
87
+ # Arguments:
88
+ # author_id: (Integer) id of author.
89
+ def author_articles(author_id)
90
+ parse(@api["/authors/#{author_id}/articles"].get(:accept => :json))
91
+ end
92
+
93
+ # Return a group of methods of statistics.
94
+ def statistics
95
+ @statistics
96
+ end
97
+
98
+ # Return a API REST client resource.
99
+ def api
100
+ @api
101
+ end
102
+
103
+ # Parse JSON to hash.
104
+ def parse(obj)
105
+ JSON.parse(obj)
106
+ end
107
+
108
+ # Group of statistics methods.
109
+ class Statistics
110
+ def initialize(parent)
111
+ @parent = parent
112
+ end
113
+
114
+ # Register statistics for specific resource.
115
+ #
116
+ # Arguments:
117
+ # params: (Hash)
118
+ # journal_id: (Integer) id of journal.
119
+ # issue_id: (Integer) id of issue.
120
+ # article_id: (Integer) id of article.
121
+ def register(params = {})
122
+ url_params = params_to_url(params)
123
+
124
+ @parent.api["/statistics/register?#{url_params}"].put :accept => :json
125
+ end
126
+
127
+ # View statistics for specifc resource.
128
+ #
129
+ # Arguments:
130
+ # params: (Hash)
131
+ # journal_id: (Integer) id of journal.
132
+ # issue_id: (Integer) id of issue.
133
+ # article_id: (Integer) id of article.
134
+ def view(params = {})
135
+ url_params = params_to_url(params)
136
+
137
+ @parent.parse(@parent.api["/statistics/view?#{url_params}"].get(:accept => :json))
138
+ end
139
+
140
+ private
141
+
142
+ # convert hash params to url parameters.
143
+ def params_to_url(params)
144
+ url_params = ''
145
+ url_params += '&journal_id=' + params[:journal_id].to_s if params[:journal_id]
146
+ url_params += '&issue_id=' + params[:issue_id].to_s if params[:issue_id]
147
+ url_params += '&article_id=' + params[:article_id].to_s if params[:article_id]
148
+ end
149
+ end
150
+
151
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsb_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Definity Solutions
8
+ - David Sobreira Gouvea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest_client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ description: A simple client to connect with Definity Journal Service Bus Server
29
+ email: developer@definitysolutions.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - jsb_client/ruby/v1/lib/jsb.rb
35
+ homepage: http://jsb.definitysolutions.com
36
+ licenses:
37
+ - Apache
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.4.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Journal Service Bus (JSB) Client
59
+ test_files: []