appoxy_api 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/api/client.rb +26 -27
  2. metadata +46 -29
data/lib/api/client.rb CHANGED
@@ -24,28 +24,37 @@ module Appoxy
24
24
  @secret_key = secret_key
25
25
  end
26
26
 
27
+ def process_ex(ex)
28
+ decoded_ex = ActiveSupport::JSON.decode(ex.http_body)
29
+ exception = Exception.new(ex.message+":"+decoded_ex["msg"])
30
+ exception.set_backtrace(decoded_ex["backtrace"].split(",")) if decoded_ex["backtrace"]
31
+ raise exception
32
+ end
27
33
 
28
34
  def get(method, params={}, options={})
29
35
  begin
30
36
  # ClientHelper.run_http(host, access_key, secret_key, :get, method, nil, params)
31
37
  parse_response RestClient.get(append_params(url(method), add_params(method, params)), headers), options
32
- rescue RestClient::BadRequest => ex
33
- # puts ex.http_body
34
- raise "Bad Request: " + ActiveSupport::JSON.decode(ex.http_body)["msg"].to_s
38
+ rescue RestClient::BadRequest, RestClient::InternalServerError => ex
39
+ process_ex(ex)
35
40
  end
36
-
37
41
  end
38
42
 
43
+ def post_file(method, file, params={}, options={})
44
+ begin
45
+ parse_response RestClient.post(url(method), add_params(method, params).merge!({:file=>file}), :multipart => true), options
46
+ rescue RestClient::BadRequest, RestClient::InternalServerError => ex
47
+ process_ex(ex)
48
+ end
49
+ end
39
50
 
40
51
  def post(method, params={}, options={})
41
52
  begin
42
53
  parse_response RestClient.post(url(method), add_params(method, params).to_json, headers), options
43
54
  #ClientHelper.run_http(host, access_key, secret_key, :post, method, nil, params)
44
- rescue RestClient::BadRequest => ex
45
- # puts ex.http_body
46
- raise "Bad Request: " + ActiveSupport::JSON.decode(ex.http_body)["msg"].to_s
55
+ rescue RestClient::BadRequest, RestClient::InternalServerError => ex
56
+ process_ex(ex)
47
57
  end
48
-
49
58
  end
50
59
 
51
60
 
@@ -53,45 +62,39 @@ module Appoxy
53
62
  begin
54
63
  parse_response RestClient.put(url(method), add_params(method, body).to_json, headers), options
55
64
  #ClientHelper.run_http(host, access_key, secret_key, :put, method, body, nil)
56
- rescue RestClient::BadRequest => ex
57
- # puts ex.http_body
58
- raise "Bad Request: " + ActiveSupport::JSON.decode(ex.http_body)["msg"].to_s
65
+ rescue RestClient::BadRequest, RestClient::InternalServerError => ex
66
+ process_ex(ex)
59
67
  end
60
68
  end
61
69
 
62
-
63
70
  def delete(method, params={}, options={})
64
71
  begin
65
72
  parse_response RestClient.delete(append_params(url(method), add_params(method, params))), options
66
- rescue RestClient::BadRequest => ex
67
- raise "Bad Request: " + ActiveSupport::JSON.decode(ex.http_body)["msg"].to_s
73
+ rescue RestClient::BadRequest, RestClient::InternalServerError => ex
74
+ process_ex(ex)
68
75
  end
69
76
  end
70
77
 
71
-
72
78
  def url(command_path)
73
79
  url = host + command_path
74
80
  url
75
81
  end
76
82
 
77
-
78
83
  def add_params(command_path, hash)
79
84
  v = version||"0.1"
80
85
  ts = Appoxy::Api::Signatures.generate_timestamp(Time.now.gmtime)
81
86
  # puts 'timestamp = ' + ts
82
87
  sig = case v
83
- when "0.2"
84
- Appoxy::Api::Signatures.generate_signature(command_path + Appoxy::Api::Signatures.hash_to_s(hash), ts, secret_key)
85
- when "0.1"
86
- Appoxy::Api::Signatures.generate_signature(command_path, ts, secret_key)
87
- end
88
+ when "0.2"
89
+ Appoxy::Api::Signatures.generate_signature(command_path + Appoxy::Api::Signatures.hash_to_s(hash), ts, secret_key)
90
+ when "0.1"
91
+ Appoxy::Api::Signatures.generate_signature(command_path, ts, secret_key)
92
+ end
88
93
 
89
94
  extra_params = {'sigv'=>v, 'sig' => sig, 'timestamp' => ts, 'access_key' => access_key}
90
95
  hash.merge!(extra_params)
91
-
92
96
  end
93
97
 
94
-
95
98
  def append_params(host, params)
96
99
  host += "?"
97
100
  i = 0
@@ -103,13 +106,11 @@ module Appoxy
103
106
  return host
104
107
  end
105
108
 
106
-
107
109
  def headers
108
110
  user_agent = "Appoxy API Ruby Client"
109
111
  headers = {'User-Agent' => user_agent}
110
112
  end
111
113
 
112
-
113
114
  def parse_response(response, options={})
114
115
  unless options[:parse] == false
115
116
  begin
@@ -123,8 +124,6 @@ module Appoxy
123
124
  end
124
125
  end
125
126
 
126
-
127
127
  end
128
-
129
128
  end
130
129
  end
metadata CHANGED
@@ -1,35 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: appoxy_api
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.10
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 11
9
+ version: 0.0.11
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Travis Reeder
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2011-03-06 00:00:00.000000000 -08:00
16
+
17
+ date: 2011-03-24 00:00:00 -07:00
13
18
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
16
21
  name: rest-client
17
- requirement: &23295948 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
18
24
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
23
31
  type: :runtime
24
- prerelease: false
25
- version_requirements: *23295948
32
+ version_requirements: *id001
26
33
  description: Appoxy API Helper gem description...
27
34
  email: travis@appoxy.com
28
35
  executables: []
36
+
29
37
  extensions: []
30
- extra_rdoc_files:
38
+
39
+ extra_rdoc_files:
31
40
  - README.markdown
32
- files:
41
+ files:
33
42
  - lib/api/client.rb
34
43
  - lib/api/client_helper.rb
35
44
  - lib/api/signatures.rb
@@ -38,26 +47,34 @@ files:
38
47
  has_rdoc: true
39
48
  homepage: http://www.appoxy.com
40
49
  licenses: []
50
+
41
51
  post_install_message:
42
52
  rdoc_options: []
43
- require_paths:
53
+
54
+ require_paths:
44
55
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
46
57
  none: false
47
- requirements:
48
- - - ! '>='
49
- - !ruby/object:Gem::Version
50
- version: '0'
51
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
65
  none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
57
72
  requirements: []
73
+
58
74
  rubyforge_project:
59
- rubygems_version: 1.6.0
75
+ rubygems_version: 1.3.7
60
76
  signing_key:
61
77
  specification_version: 3
62
78
  summary: Appoxy API Helper gem
63
79
  test_files: []
80
+