metwit 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -46,6 +46,9 @@ metag = Metwit::Metag.find('id')
46
46
 
47
47
  ## How to get metags in a geographical region
48
48
  metags = Metwit::Metag.in_rect(45.4, 9.1, 45.3, 9.0)
49
+
50
+ ## How to get last metags
51
+ metags = Metwit::Metag.feed
49
52
  ```
50
53
 
51
54
  ## Contributing
data/lib/metwit/auth.rb CHANGED
@@ -18,7 +18,7 @@ module Metwit
18
18
  @logged = false
19
19
  url = BASE_URL + '/auth/'
20
20
 
21
- response = HTTParty.post(url, :body => {:username=>username, :password=>password}, :headers => {'Authorization' => "Bearer #{@api_key}"})
21
+ response = HTTParty.post(url, :body => {:username=>username, :password=>password}.to_json, :headers => {'Authorization' => "Bearer #{@api_key}"})
22
22
  @access_token = response['bearer_token']
23
23
  @logged = true if response.code == 200
24
24
  response
data/lib/metwit/metag.rb CHANGED
@@ -9,7 +9,6 @@ module Metwit
9
9
  class Metag
10
10
  include HTTParty
11
11
  base_uri(BASE_URL+'/metags')
12
- headers 'Authorization' => "Bearer #{Metwit.bearer_token}"
13
12
 
14
13
  # Mandatory and guaranteed.
15
14
  # Weather is an Hash with two keys: :status and :details
@@ -108,7 +107,7 @@ module Metwit
108
107
  # This metod POST a metag
109
108
  def create!
110
109
  raise "invalid metag" unless self.valid?
111
- response = self.class.post('/', :body => self.to_json, :headers => {'Cookie' => Metwit.cookie, 'Content-Type' => 'application/json' })
110
+ response = self.class.post('/', authenticated(:body => self.to_json, :headers => {'Content-Type' => 'application/json'}))
112
111
  raise "post failed" unless response.code == 201
113
112
  response
114
113
  end
@@ -117,22 +116,35 @@ module Metwit
117
116
  # Return the metag associated with the id
118
117
  # @return [Metag]
119
118
  def find(id)
120
- response = get("/#{id}/")
119
+ response = get("/#{id}/", authenticated({}))
121
120
  raise "http error" unless response.code == 200
122
121
  self.from_json(response)
123
122
  end
124
123
 
125
124
  # Return metags in a geographical region
126
- # return [Array<Metag>]
125
+ # @return [Array<Metag>]
127
126
  def in_rect(lat_n, lng_w, lat_s, lng_e)
128
- response = get('/', :query => {:rect => "#{lat_n},#{lng_w},#{lat_s},#{lng_e}"})
127
+ response = get('/', authenticated(:query => {:rect => "#{lat_n},#{lng_w},#{lat_s},#{lng_e}"}))
128
+ raise "in_rect error" unless response.code == 200
129
129
  metags = []
130
130
  response['objects'].each do |metag_json|
131
131
  metags << self.from_json(metag_json)
132
132
  end
133
133
  metags
134
134
  end
135
-
135
+
136
+ # Return last metags posted
137
+ # @return [Array<Metag>]
138
+ def feed
139
+ response = get('/', authenticated({}))
140
+ raise "feed error" unless response.code == 200
141
+ metags = []
142
+ response['objects'].each do |metag_json|
143
+ metags << self.from_json(metag_json)
144
+ end
145
+ metags
146
+ end
147
+
136
148
  # Return a metag form a JSON response
137
149
  # @return [User]
138
150
  def from_json(response)
@@ -147,7 +159,21 @@ module Metwit
147
159
  }
148
160
  Metag.new(args)
149
161
  end
150
-
162
+
163
+ private
164
+ # Default HTTParty options
165
+ # @return [Hash]
166
+ def authenticated(opts)
167
+ opts.deep_merge(:headers => {'Authorization' => "Bearer #{Metwit.bearer_token}"})
168
+ end
169
+
170
+ end
171
+
172
+ private
173
+ # HTTParty options for authenticaded calls
174
+ # @return [Hash]
175
+ def authenticated(opts)
176
+ self.class.authenticated(opts)
151
177
  end
152
178
 
153
179
  end
data/lib/metwit/user.rb CHANGED
@@ -93,7 +93,7 @@ module Metwit
93
93
  # Return the user associated with the id
94
94
  # @return [User]
95
95
  def find(id)
96
- response = get("/#{id}/")
96
+ response = get("/#{id}/", authenticated({}))
97
97
  raise "http error" unless response.code == 200
98
98
  self.from_json(response)
99
99
  end
@@ -115,8 +115,21 @@ module Metwit
115
115
  }
116
116
  User.new(args)
117
117
  end
118
-
118
+
119
+ private
120
+ # Default HTTParty options
121
+ # @return [Hash]
122
+ def authenticated(opts)
123
+ opts.deep_merge(:headers => {'Authorization' => "Bearer #{Metwit.bearer_token}"})
124
+ end
119
125
  end
120
-
126
+
127
+ private
128
+ # HTTParty options for authenticaded calls
129
+ # @return [Hash]
130
+ def authenticated(opts)
131
+ self.class.authenticated(opts)
132
+ end
133
+
121
134
  end
122
135
  end
@@ -1,4 +1,4 @@
1
1
  module Metwit
2
2
  # The version of the metwit gem
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
data/lib/metwit.rb CHANGED
@@ -3,7 +3,7 @@ require "metwit/constants"
3
3
  require "metwit/version"
4
4
  require "metwit/metag"
5
5
  require "metwit/user"
6
-
6
+ require 'active_support/all'
7
7
 
8
8
  # All classes are qualified in the namespace Metwit
9
9
  module Metwit
data/metwit.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Metwit::VERSION
17
17
  gem.add_dependency('httparty')
18
18
  gem.add_dependency('rgeo-geojson')
19
+ gem.add_dependency('activesupport')
19
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metwit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: Ruby SDK for Metwit public APIs
47
63
  email:
48
64
  - sim@me.com