tuppari 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .DS_Store
6
6
  .idea
7
+ bin/
data/README.md CHANGED
@@ -40,7 +40,7 @@ open('tuppari.html', 'w') do |f|
40
40
  html = <<"EOF"
41
41
  <html>
42
42
  <head>
43
- <script src="http://cdn.tuppari.com/0.1.0/tuppari.min.js"></script>
43
+ <script src="http://cdn.tuppari.com/0.2.0/tuppari.min.js"></script>
44
44
  <script>
45
45
  var client, channel;
46
46
  client = tuppari.createClient({applicationId: '#{application.id}'});
@@ -79,9 +79,9 @@ Tuppari account authentication is not needed for publishing messages. And follow
79
79
 
80
80
  ```ruby
81
81
  application = Tuppari::Application.new(
82
- :id => 'xxxx',
83
- :access_key_id => 'yyy',
84
- :access_secret_key => 'zzz'
82
+ :id => '4032236d-699a-4599-9405-xxxxxxxxxxxx',
83
+ :access_key_id => 'b49049f9-e055-4fa5-925b-xxxxxxxxxxxx',
84
+ :access_secret_key => 'c01a3a31-92cd-4bf9-a238-xxxxxxxxxxxx'
85
85
  ) # or application = tuppari.get_application('first-tuppari')
86
86
 
87
87
  Tuppari.publish_message(
@@ -9,7 +9,7 @@ require 'tuppari/application'
9
9
  require 'tuppari/authentication_error'
10
10
  require 'tuppari/client'
11
11
  require 'tuppari/client_error'
12
- require 'tuppari/server_url'
12
+ require 'tuppari/gyoji_server_spec'
13
13
 
14
14
  # Tuppari API client
15
15
  #
@@ -1,11 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ require 'tuppari/gyoji_server_spec'
4
+
3
5
  module Tuppari
4
6
  class Application
5
7
 
6
- attr_accessor :name, :id, :access_key_id, :access_secret_key
8
+ attr_accessor :gyoji_base_url, :name, :id, :access_key_id, :access_secret_key
7
9
 
8
10
  def initialize(params)
11
+ @gyoji_base_url = GyojiServerSpec::DEFAULT_GYOJI_BASE_URL
9
12
  @name = params[:name]
10
13
  @id = params[:id]
11
14
  @access_key_id = params[:access_key_id]
@@ -10,11 +10,12 @@ require 'tuppari'
10
10
  module Tuppari
11
11
  class Client
12
12
 
13
- attr_accessor :account_name, :account_secret, :application, :log
13
+ attr_accessor :gyoji_base_url, :account_name, :account_secret, :application, :log
14
14
 
15
15
  def initialize(params = {})
16
16
  @log = Logger.new(params[:log_output] || STDOUT)
17
17
  @log.level = params[:log_level] || Logger::INFO
18
+ @gyoji_base_url = params[:gyoji_base_url] || GyojiServerSpec::DEFAULT_GYOJI_BASE_URL
18
19
  @account_name = params[:account_name]
19
20
  @account_secret = params[:account_secret]
20
21
  setup_application(params)
@@ -28,7 +29,8 @@ module Tuppari
28
29
  def create_account(account_name, password)
29
30
  body = JSON.unparse({"accountName" => account_name, "password" => password})
30
31
  begin
31
- RestClient.post(Tuppari::ServerURL::ACCOUNTS_REGISTER, body, :content_type => :json)
32
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::ACCOUNTS_REGISTER_PATH
33
+ RestClient.post(url, body, :content_type => :json)
32
34
  rescue RestClient::Exception => e
33
35
  @log.warn("Failed to create a new Tuppari account (#{e}, #{e.http_body})")
34
36
  raise e
@@ -41,7 +43,8 @@ module Tuppari
41
43
  def login(account_name, password)
42
44
  body = JSON.unparse({:accountName => account_name, :password => password})
43
45
  begin
44
- body = RestClient.post(Tuppari::ServerURL::ACCOUNTS_AUTH, body, :content_type => :json)
46
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::ACCOUNTS_AUTH_PATH
47
+ body = RestClient.post(url, body, :content_type => :json)
45
48
  credentials = JSON.parse(body)['credentials']
46
49
  @account_name = credentials['id']
47
50
  @account_secret = credentials['secret']
@@ -70,11 +73,12 @@ module Tuppari
70
73
  time = Time.now
71
74
  headers = headers('CreateApplication', time)
72
75
  body_params = {:applicationName => application_name.to_s}
76
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::APPLICATIONS_PATH
73
77
  auth_header = Tuppari::Auth.create_authorization_header(
74
78
  :id => @account_name,
75
79
  :secret => @account_secret,
76
80
  :method => 'POST',
77
- :uri => Tuppari::ServerURL::APPLICATIONS,
81
+ :uri => url,
78
82
  :host => 'api.tuppari.com',
79
83
  :query_string => '',
80
84
  :headers => headers,
@@ -82,9 +86,7 @@ module Tuppari
82
86
  :request_time => time
83
87
  )
84
88
  begin
85
- body = RestClient.post(Tuppari::ServerURL::APPLICATIONS,
86
- JSON.unparse(body_params),
87
- headers.merge(:authorization => auth_header))
89
+ body = RestClient.post(url, JSON.unparse(body_params), headers.merge(:authorization => auth_header))
88
90
  @log.debug {
89
91
  "create_application response: #{body}"
90
92
  }
@@ -115,11 +117,12 @@ module Tuppari
115
117
  time = Time.now
116
118
  headers = headers('DeleteApplication', time)
117
119
  body_params = {:applicationName => application_name}
120
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::APPLICATIONS_PATH
118
121
  auth_header = Tuppari::Auth.create_authorization_header(
119
122
  :id => @account_name,
120
123
  :secret => @account_secret,
121
124
  :method => 'POST',
122
- :uri => Tuppari::ServerURL::APPLICATIONS,
125
+ :uri => url,
123
126
  :host => 'api.tuppari.com',
124
127
  :query_string => '',
125
128
  :headers => headers,
@@ -127,9 +130,7 @@ module Tuppari
127
130
  :request_time => time
128
131
  )
129
132
  begin
130
- RestClient.post(Tuppari::ServerURL::APPLICATIONS,
131
- JSON.unparse(body_params),
132
- headers.merge(:authorization => auth_header))
133
+ RestClient.post(url, JSON.unparse(body_params), headers.merge(:authorization => auth_header))
133
134
  @log.info {
134
135
  "Tuppari application is deleted. (#{application_name})"
135
136
  }
@@ -155,11 +156,12 @@ module Tuppari
155
156
  time = Time.now
156
157
  headers = headers('ListApplication', time)
157
158
  body_params = {}
159
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::APPLICATIONS_PATH
158
160
  auth_header = Tuppari::Auth.create_authorization_header(
159
161
  :id => @account_name,
160
162
  :secret => @account_secret,
161
163
  :method => 'POST',
162
- :uri => Tuppari::ServerURL::APPLICATIONS,
164
+ :uri => url,
163
165
  :host => 'api.tuppari.com',
164
166
  :query_string => '',
165
167
  :headers => headers,
@@ -167,9 +169,7 @@ module Tuppari
167
169
  :request_time => time
168
170
  )
169
171
  begin
170
- body = RestClient.post(Tuppari::ServerURL::APPLICATIONS,
171
- JSON.unparse(body_params),
172
- headers.merge(:authorization => auth_header))
172
+ body = RestClient.post(url, JSON.unparse(body_params), headers.merge(:authorization => auth_header))
173
173
  @log.debug {
174
174
  "get_application_list response: #{response}"
175
175
  }
@@ -209,11 +209,12 @@ module Tuppari
209
209
  :event => event,
210
210
  :message => message
211
211
  }
212
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::MESSAGES_PATH
212
213
  auth_header = Tuppari::Auth.create_authorization_header(
213
214
  :id => @application.access_key_id,
214
215
  :secret => @application.access_secret_key,
215
216
  :method => 'POST',
216
- :uri => Tuppari::ServerURL::MESSAGES,
217
+ :uri => url,
217
218
  :host => 'api.tuppari.com',
218
219
  :query_string => '',
219
220
  :headers => headers,
@@ -221,9 +222,7 @@ module Tuppari
221
222
  :request_time => time
222
223
  )
223
224
  begin
224
- body = RestClient.post(Tuppari::ServerURL::MESSAGES,
225
- JSON.unparse(body_params),
226
- headers.merge(:authorization => auth_header))
225
+ body = RestClient.post(url, JSON.unparse(body_params), headers.merge(:authorization => auth_header))
227
226
  @log.debug {
228
227
  "Tuppari message has been sent. (#{@application.id},#{channel},#{event},#{message})"
229
228
  }
@@ -245,7 +244,8 @@ module Tuppari
245
244
 
246
245
  def get_service_info()
247
246
  begin
248
- body = RestClient.get(Tuppari::ServerURL::INFO, 'Content-type' => 'application/json')
247
+ url = get_gyoji_base_url() + Tuppari::GyojiServerSpec::INFO_PATH
248
+ body = RestClient.get(url, 'Content-type' => 'application/json')
249
249
  JSON.parse(body)
250
250
  rescue RestClient::Exception => e
251
251
  @log.warn("Failed to get the Tuppari service info (#{e}, #{e.http_body})")
@@ -277,6 +277,14 @@ module Tuppari
277
277
  end
278
278
  end
279
279
 
280
+ def get_gyoji_base_url()
281
+ if @application.nil?
282
+ @gyoji_base_url
283
+ else
284
+ @application.gyoji_base_url
285
+ end
286
+ end
287
+
280
288
  def headers(operation, time)
281
289
  {
282
290
  'Host' => 'api.tuppari.com',
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Tuppari
4
+ module GyojiServerSpec
5
+
6
+ DEFAULT_GYOJI_BASE_URL = 'https://api.tuppari.com'
7
+
8
+ ACCOUNTS_REGISTER_PATH = '/accounts/register'
9
+ ACCOUNTS_AUTH_PATH = '/accounts/auth'
10
+ APPLICATIONS_PATH = '/applications'
11
+ MESSAGES_PATH = '/messages'
12
+ INFO_PATH = '/info'
13
+
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module Tuppari
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuppari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-14 00:00:00.000000000 Z
12
+ date: 2012-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -60,7 +60,7 @@ files:
60
60
  - lib/tuppari/authentication_error.rb
61
61
  - lib/tuppari/client.rb
62
62
  - lib/tuppari/client_error.rb
63
- - lib/tuppari/server_url.rb
63
+ - lib/tuppari/gyoji_server_spec.rb
64
64
  - lib/tuppari/version.rb
65
65
  - spec/README.md
66
66
  - spec/tuppari/auth_spec.rb
@@ -1,19 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module Tuppari
4
- module ServerURL
5
-
6
- BASE_URL = 'https://api.tuppari.com'
7
-
8
- ACCOUNTS_REGISTER = BASE_URL + '/accounts/register'
9
-
10
- ACCOUNTS_AUTH = BASE_URL + '/accounts/auth'
11
-
12
- APPLICATIONS = BASE_URL + '/applications'
13
-
14
- MESSAGES = BASE_URL + '/messages'
15
-
16
- INFO = BASE_URL + '/info'
17
-
18
- end
19
- end