jawbone-up 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,14 @@
1
- libdir = File.dirname(__FILE__)
2
1
  require 'json'
3
2
  require 'faraday'
4
- require './lib/jawbone-up/error.rb'
5
- require './lib/jawbone-up/config.rb'
6
- require './lib/jawbone-up/response.rb'
7
- require './lib/jawbone-up/session.rb'
3
+ require 'jawbone-up/error.rb'
4
+ require 'jawbone-up/config.rb'
5
+ require 'jawbone-up/response.rb'
6
+ require 'jawbone-up/session.rb'
7
+ # libdir = File.dirname(__FILE__)
8
+ # require "#{libdir}/jawbone-up/error.rb"
9
+ # require "#{libdir}/jawbone-up/config.rb"
10
+ # require "#{libdir}/jawbone-up/response.rb"
11
+ # require "#{libdir}/jawbone-up/session.rb"
8
12
 
9
13
  module JawboneUP
10
14
  @@adapter = :net_http
@@ -1,3 +1,5 @@
1
+ require 'rest-client'
2
+
1
3
  module JawboneUP
2
4
  class Session
3
5
  attr_reader :auth
@@ -9,10 +11,6 @@ module JawboneUP
9
11
  self.auth = opts[:auth] || {}
10
12
  self.auth[:token] = opts[:token] if opts[:token]
11
13
  self.auth[:xid] = opts[:xid] if opts[:xid]
12
-
13
- @connection = Faraday.new(:url => JawboneUP.api_url) do |builder|
14
- builder.adapter :net_http
15
- end
16
14
  end
17
15
 
18
16
  def auth=(hash)
@@ -87,7 +85,7 @@ module JawboneUP
87
85
  end
88
86
 
89
87
  def execute(meth, path, query=nil, headers={})
90
- query = Rack::Utils.parse_query query if query.is_a?(String)
88
+ query = CGI::parse(query) if query.is_a?(String)
91
89
  headers = default_headers.merge! headers
92
90
 
93
91
  if @config.logger
@@ -98,33 +96,30 @@ module JawboneUP
98
96
  @config.logger.print "\n\n"
99
97
  end
100
98
 
101
- raw = @connection.send(meth) do |req|
102
- req.url "/#{path.gsub(/^\//, '')}"
103
- req.headers = headers
104
- if query
105
- meth == :get ? req.params = query : req.body = URI.encode_www_form(query)
106
- end
99
+ if meth == :get
100
+ response = RestClient.get "#{JawboneUP.api_url}/#{path.gsub(/^\//, '')}", headers.merge({:params => query})
101
+ else
102
+ response = RestClient.post "#{JawboneUP.api_url}/#{path.gsub(/^\//, '')}", query, headers
107
103
  end
108
104
 
109
- if raw.status != 200
105
+ if response.code != 200
110
106
  begin
111
- error = JSON.parse raw.body
107
+ error = JSON.parse response.to_str
112
108
  raise JSON::ParserError.new if error['meta'].nil? || error['meta']['error_type'].nil?
113
- raise ApiError.new(raw.status, error['meta']['error_type'], error['meta']['error_detail'])
109
+ raise ApiError.new(response.code, error['meta']['error_type'], error['meta']['error_detail'])
114
110
  rescue JSON::ParserError => e
115
- raise ApiError.new(raw.status, "error", "Unknown API error") if raw.status != 200
111
+ raise ApiError.new(response.code, "error", "Unknown API error") if response.code != 200
116
112
  end
117
113
  end
118
114
 
119
115
  if @config.logger
120
116
  @config.logger.print "### JawboneUp::Session - #{meth.to_s.upcase} #{path}"
121
- @config.logger.print "?#{Rack::Utils.build_query query}" unless query.nil?
117
+ @config.logger.print query.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join("&")
122
118
  @config.logger.print "\n### Request Headers: #{headers.inspect}"
123
- @config.logger.print "### Status: #{raw.status}\n### Headers: #{raw.headers.inspect}\n###"
124
- # @config.logger.puts "Body: #{raw.body}"
119
+ @config.logger.print "### Status: #{response.code}\n### Headers: #{response.headers.inspect}\n###"
125
120
  end
126
121
 
127
- Response.new raw.status, raw.headers, raw.body
122
+ Response.new response.code, response.headers, response.to_str
128
123
  end
129
124
 
130
125
  def default_headers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jawbone-up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-01 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-06-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  description: A client for the Jawbone UP service, as discovered by http://eric-blue.com/projects/up-api/
15
47
  email: aaron@parecki.com
16
48
  executables: []
@@ -22,7 +54,7 @@ files:
22
54
  - lib/jawbone-up/session.rb
23
55
  - lib/jawbone-up/error.rb
24
56
  - lib/jawbone-up/config.rb
25
- homepage: http://eric-blue.com/projects/up-api/
57
+ homepage: https://github.com/aaronpk/jawbone-up-ruby
26
58
  licenses: []
27
59
  post_install_message:
28
60
  rdoc_options: []