metwit 0.0.1 → 0.0.2
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/.yardopts +1 -0
- data/Gemfile +8 -0
- data/README.md +29 -1
- data/Rakefile +7 -0
- data/lib/metwit.rb +6 -1
- data/lib/metwit/auth.rb +32 -0
- data/lib/metwit/constants.rb +3 -0
- data/lib/metwit/metag.rb +154 -0
- data/lib/metwit/user.rb +122 -0
- data/lib/metwit/version.rb +2 -1
- data/metwit.gemspec +2 -0
- data/spec/fixtures/metag1234 +9 -0
- data/spec/fixtures/user6576 +9 -0
- data/spec/metwit/metag_spec.rb +174 -0
- data/spec/metwit/user_spec.rb +103 -0
- data/spec/spec_helper.rb +18 -0
- metadata +51 -4
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-m markdown
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,35 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
# First require the gem
|
23
|
+
require 'metwit'
|
24
|
+
|
25
|
+
# Set your api key
|
26
|
+
Metwit.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
27
|
+
|
28
|
+
## How to post a Metag
|
29
|
+
# If you don't authenticate a user you may not be able to post metags
|
30
|
+
Metwit.authenticate("username", "password")
|
31
|
+
# You need a rgeo factory to project the point coordinates
|
32
|
+
factory = RGeo::Cartesian.factory
|
33
|
+
# Then you can create a basic metag
|
34
|
+
metag = Metwit::Metag.new(
|
35
|
+
:weather => {:status => :clear},
|
36
|
+
:position => factory.point(45.4, 9.1)
|
37
|
+
)
|
38
|
+
# Then post it to the server
|
39
|
+
metag.create!
|
40
|
+
|
41
|
+
## How to get a user by id
|
42
|
+
user = Metwit::User.find('id')
|
43
|
+
|
44
|
+
## How to get a metag by id
|
45
|
+
metag = Metwit::Metag.find('id')
|
46
|
+
|
47
|
+
## How to get metags in a geographical region
|
48
|
+
metags = Metwit::Metag.in_rect(45.4, 9.1, 45.3, 9.0)
|
49
|
+
```
|
22
50
|
|
23
51
|
## Contributing
|
24
52
|
|
data/Rakefile
CHANGED
data/lib/metwit.rb
CHANGED
data/lib/metwit/auth.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Metwit
|
2
|
+
class << self
|
3
|
+
|
4
|
+
# The developer api key
|
5
|
+
attr_accessor :api_key
|
6
|
+
|
7
|
+
# The user access token
|
8
|
+
attr_accessor :access_token
|
9
|
+
|
10
|
+
# Tell if login was successuful
|
11
|
+
# @return [Boolean]
|
12
|
+
def logged?
|
13
|
+
@logged ||= false
|
14
|
+
end
|
15
|
+
|
16
|
+
# Exchange the developer api key for a user access token
|
17
|
+
def authenticate(username, password)
|
18
|
+
@logged = false
|
19
|
+
url = BASE_URL + '/auth/'
|
20
|
+
|
21
|
+
response = HTTParty.post(url, :body => {:username=>username, :password=>password}, :headers => {'Authorization' => "Bearer #{@api_key}"})
|
22
|
+
@access_token = response['bearer_token']
|
23
|
+
@logged = true if response.code == 200
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
def bearer_token
|
28
|
+
self.logged? ? @access_token : @api_key
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/metwit/metag.rb
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'rgeo'
|
2
|
+
require 'rgeo-geojson'
|
3
|
+
require 'httparty'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Metwit
|
7
|
+
|
8
|
+
# Metags are the weather tags
|
9
|
+
class Metag
|
10
|
+
include HTTParty
|
11
|
+
base_uri(BASE_URL+'/metags')
|
12
|
+
headers 'Authorization' => "Bearer #{Metwit.bearer_token}"
|
13
|
+
|
14
|
+
# Mandatory and guaranteed.
|
15
|
+
# Weather is an Hash with two keys: :status and :details
|
16
|
+
# Valid :status values are:
|
17
|
+
# :clear, :rainy, :stormy, :snowy, :partly\_cloudy, :cloudy, :hailing, :heavy\_seas, :calm\_seas, :foggy, :snow\_flurries, :windy, :partly\_cloudy, :uknown
|
18
|
+
# @return [{Symbol => String, Hash}] weather data
|
19
|
+
attr_accessor :weather
|
20
|
+
|
21
|
+
# Guaranteed.
|
22
|
+
# The metag id
|
23
|
+
# @return [String] unique identifier of the metag
|
24
|
+
attr_reader :id
|
25
|
+
|
26
|
+
# Guaranteed.
|
27
|
+
# The metag timestamp.
|
28
|
+
# @return [Time] when the metag was created
|
29
|
+
attr_reader :timestamp
|
30
|
+
|
31
|
+
# Mandatory and guaranteed.
|
32
|
+
# The geo location of the metag with GeoJSON format
|
33
|
+
# @return [RGeo::Feature::Point] geo location of the metag
|
34
|
+
attr_accessor :position
|
35
|
+
|
36
|
+
# Guaranteed.
|
37
|
+
# The issuer of the metag.
|
38
|
+
# @return [User] the issuer of the metag
|
39
|
+
attr_accessor :user
|
40
|
+
|
41
|
+
# Guaranteed.
|
42
|
+
# The number of replies
|
43
|
+
# @return [Fixnum] the number of replies
|
44
|
+
attr_accessor :replies_count
|
45
|
+
|
46
|
+
# Guaranteed
|
47
|
+
# The number of thanks
|
48
|
+
# @return [Fixnum] the number of thanks
|
49
|
+
attr_accessor :thanks_count
|
50
|
+
|
51
|
+
|
52
|
+
def initialize(args={})
|
53
|
+
@id = args[:id]
|
54
|
+
@weather = args[:weather]
|
55
|
+
@position = args[:position]
|
56
|
+
@timestamp = args[:timestamp]
|
57
|
+
@weather = args[:weather]
|
58
|
+
@user = args[:user]
|
59
|
+
@replies_count = args[:replies_count]
|
60
|
+
@thanks_count = args[:thanks_count]
|
61
|
+
end
|
62
|
+
|
63
|
+
# This method validates the metag for the submission
|
64
|
+
# @return [Boolean]
|
65
|
+
def valid?
|
66
|
+
return false unless weather_valid?
|
67
|
+
return false unless position_valid?
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
# This method check if the weathear is valid
|
72
|
+
# @return [Boolean]
|
73
|
+
def weather_valid?
|
74
|
+
return false if @weather.nil?
|
75
|
+
return false if @weather[:status].nil?
|
76
|
+
return false unless weather_statuses.include?(@weather[:status])
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
# This method check if the position is valid
|
81
|
+
# @return [Boolean]
|
82
|
+
def position_valid?
|
83
|
+
return false if @position.nil?
|
84
|
+
return false unless RGeo::Feature::Point.check_type(@position)
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
# This method return all the reognized weather statuses
|
90
|
+
# @return [Array<Symbol>]
|
91
|
+
def weather_statuses
|
92
|
+
[:clear, :rainy, :stormy, :snowy, :partly_cloudy, :cloudy, :hailing, :heavy_seas, :calm_seas, :foggy, :snow_flurries, :windy, :partly_cloudy]
|
93
|
+
end
|
94
|
+
|
95
|
+
# This method encode metag in json for submission
|
96
|
+
# @return [String]
|
97
|
+
def to_json
|
98
|
+
raise "metag in invalid" unless valid?
|
99
|
+
|
100
|
+
{
|
101
|
+
weather: {
|
102
|
+
status: self.weather[:status].to_s.gsub(/_/,' '),
|
103
|
+
},
|
104
|
+
geo: RGeo::GeoJSON.encode(self.position),
|
105
|
+
}.to_json
|
106
|
+
end
|
107
|
+
|
108
|
+
# This metod POST a metag
|
109
|
+
def create!
|
110
|
+
raise "invalid metag" unless self.valid?
|
111
|
+
response = self.class.post('/', :body => self.to_json, :headers => {'Cookie' => Metwit.cookie, 'Content-Type' => 'application/json' })
|
112
|
+
raise "post failed" unless response.code == 201
|
113
|
+
response
|
114
|
+
end
|
115
|
+
|
116
|
+
class << self
|
117
|
+
# Return the metag associated with the id
|
118
|
+
# @return [Metag]
|
119
|
+
def find(id)
|
120
|
+
response = get("/#{id}/")
|
121
|
+
raise "http error" unless response.code == 200
|
122
|
+
self.from_json(response)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Return metags in a geographical region
|
126
|
+
# return [Array<Metag>]
|
127
|
+
def in_rect(lat_n, lng_w, lat_s, lng_e)
|
128
|
+
response = get('/', :query => {:rect => "#{lat_n},#{lng_w},#{lat_s},#{lng_e}"})
|
129
|
+
metags = []
|
130
|
+
response['objects'].each do |metag_json|
|
131
|
+
metags << self.from_json(metag_json)
|
132
|
+
end
|
133
|
+
metags
|
134
|
+
end
|
135
|
+
|
136
|
+
# Return a metag form a JSON response
|
137
|
+
# @return [User]
|
138
|
+
def from_json(response)
|
139
|
+
args = {
|
140
|
+
id: response['id'],
|
141
|
+
timestamp: Time.parse(response['timestamp']),
|
142
|
+
weather: {status: response['weather']['status'].gsub(/ /, '_').to_sym},
|
143
|
+
position: RGeo::GeoJSON.decode(response['geo']),
|
144
|
+
user: User.from_json(response['user']),
|
145
|
+
replies_count: response['replies_count'],
|
146
|
+
thanks_count: response['thanks_count'],
|
147
|
+
}
|
148
|
+
Metag.new(args)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
data/lib/metwit/user.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Metwit
|
4
|
+
|
5
|
+
# A user of Metwit
|
6
|
+
class User
|
7
|
+
include HTTParty
|
8
|
+
base_uri(BASE_URL+'/users')
|
9
|
+
headers 'Authorization' => "Bearer #{Metwit.bearer_token}"
|
10
|
+
|
11
|
+
# Guaranteed.
|
12
|
+
# The user id
|
13
|
+
# @return [String] unique identifier of the user
|
14
|
+
attr_reader :id
|
15
|
+
|
16
|
+
# Guaranteed.
|
17
|
+
# The user nickname
|
18
|
+
# @return [String] nickname
|
19
|
+
attr_accessor :nickname
|
20
|
+
|
21
|
+
# Guaranteed.
|
22
|
+
# Total number of metags sent by the user
|
23
|
+
# @return [Fixnum] total number of metags
|
24
|
+
attr_reader :metags_count
|
25
|
+
|
26
|
+
# Guaranteed.
|
27
|
+
# Number of metags sent today by the user
|
28
|
+
# @return [Fixnum] today metags number
|
29
|
+
attr_reader :today_metags_count
|
30
|
+
|
31
|
+
# Guaranteed.
|
32
|
+
# Avatar url
|
33
|
+
# @return [URI] avatar url
|
34
|
+
attr_accessor :avatar
|
35
|
+
|
36
|
+
# Guaranteed.
|
37
|
+
# Tells if you follow the user
|
38
|
+
# @return [Boolean]
|
39
|
+
def followed?
|
40
|
+
@is_followed
|
41
|
+
end
|
42
|
+
|
43
|
+
# Guaranteed.
|
44
|
+
# Followers count
|
45
|
+
# @return [Fixnum] The number of followers
|
46
|
+
attr_reader :followers_count
|
47
|
+
|
48
|
+
# Guaranteed.
|
49
|
+
# Following count
|
50
|
+
# @return [Fixnum] The number of following users
|
51
|
+
attr_reader :following_count
|
52
|
+
|
53
|
+
# Sport activities
|
54
|
+
# @return [Array<Symbol>] Sport activities array
|
55
|
+
attr_accessor :activities
|
56
|
+
|
57
|
+
# The badges the user earned
|
58
|
+
# @return [Array<Symbol>] Bagdges
|
59
|
+
attr_accessor :badges
|
60
|
+
|
61
|
+
# Guaranteed.
|
62
|
+
# Tells if the user is connected with facebook
|
63
|
+
# @return [Boolean]
|
64
|
+
def facebook?
|
65
|
+
@has_facebook
|
66
|
+
end
|
67
|
+
|
68
|
+
# Guaranteed.
|
69
|
+
# Tells if the user is connected with twitter
|
70
|
+
def twitter?
|
71
|
+
@has_twitter
|
72
|
+
end
|
73
|
+
|
74
|
+
# Personal
|
75
|
+
# The user email
|
76
|
+
# @return [String]
|
77
|
+
attr_accessor :email
|
78
|
+
|
79
|
+
def initialize(args={})
|
80
|
+
@id = args[:id]
|
81
|
+
@nickname = args[:nickname]
|
82
|
+
@metags_count = args[:metags_count]
|
83
|
+
@today_metags_count = args[:today_metags_count]
|
84
|
+
@avatar = args[:avatar]
|
85
|
+
@is_followed = args[:followed]
|
86
|
+
@followers_count = args[:followers_count]
|
87
|
+
@following_count = args[:following_count]
|
88
|
+
@has_facebook = args[:has_facebook]
|
89
|
+
@has_twitter = args[:has_twitter]
|
90
|
+
end
|
91
|
+
|
92
|
+
class << self
|
93
|
+
# Return the user associated with the id
|
94
|
+
# @return [User]
|
95
|
+
def find(id)
|
96
|
+
response = get("/#{id}/")
|
97
|
+
raise "http error" unless response.code == 200
|
98
|
+
self.from_json(response)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Create a user from an HTTParty::Response
|
102
|
+
# @return [User]
|
103
|
+
def from_json(response)
|
104
|
+
args = {
|
105
|
+
id: response['id'],
|
106
|
+
nickname: response['nickname'],
|
107
|
+
metags_count: response['reports_count'],
|
108
|
+
today_metags_count: response['todays_reports_count'],
|
109
|
+
avatar: URI.parse(response['avatar_url']),
|
110
|
+
followed: response['is_followed'],
|
111
|
+
followers_count: response['followers_count'],
|
112
|
+
following_count: response['following_count'],
|
113
|
+
has_facebook: response['has_facebook'],
|
114
|
+
has_twitter: response['has_twitter'],
|
115
|
+
}
|
116
|
+
User.new(args)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
data/lib/metwit/version.rb
CHANGED
data/metwit.gemspec
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
HTTP/1.0 200 OK
|
2
|
+
Date: Thu, 19 Jul 2012 20:00:13 GMT
|
3
|
+
Server: WSGIServer/0.1 Python/2.7.1
|
4
|
+
Vary: Accept-Language, Cookie
|
5
|
+
Content-Type: application/json; charset=utf-8
|
6
|
+
Content-Language: en-us
|
7
|
+
Set-Cookie: sessionid=223bcf639c1bf9a552a4745fdc8f1c2f; expires=Sun, 17-Jul-2022 20:00:13 GMT; Max-Age=315360000; Path=/
|
8
|
+
|
9
|
+
{"country": "United States", "geo": {"coordinates": [-122.40641784667969, 37.78583526611328], "type": "Point"}, "icon": "http://api.metwit.me/v2/icons/sunny", "id": "1234", "locality": "San Francisco", "replies_count": 0, "resource_uri": "/v2/metags/1/", "thanks_count": 0, "timestamp": "2012-07-13T15:53:34.250591", "user": {"activities": [], "avatar_url": "https://s3-eu-west-1.amazonaws.com/nuvola-static-eu/avatar/avatar.jpeg", "favorite_weather": "sunny", "followers_count": 0, "following_count": 0, "gender": "N", "has_facebook": false, "has_twitter": false, "id": "6576", "nickname": "davider", "reports_count": 0, "resource_uri": "/v2/users/6576/", "todays_reports_count": 3, "username": "davider", "is_followed": false}, "weather": {"status": "clear"}, "weight": -525998.758139}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
HTTP/1.0 200 OK
|
2
|
+
Date: Wed, 18 Jul 2012 20:18:03 GMT
|
3
|
+
Server: WSGIServer/0.1 Python/2.7.1
|
4
|
+
Vary: Accept-Language, Cookie
|
5
|
+
Content-Type: application/json; charset=utf-8
|
6
|
+
Content-Language: en-us
|
7
|
+
Set-Cookie: sessionid=acd2192c9f992cf424520af41bacab1b; expires=Sat, 16-Jul-2022 20:18:03 GMT; Max-Age=315360000; Path=/
|
8
|
+
|
9
|
+
{"activities": [], "avatar_url": "https://s3-eu-west-1.amazonaws.com/nuvola-static-eu/avatar/avatar.jpeg", "favorite_weather": "sunny", "followers_count": 0, "following_count": 0, "gender": "N", "has_facebook": false, "has_twitter": false, "id": "6576", "nickname": "davider", "reports_count": 0, "resource_uri": "/v2/users/6576/", "todays_reports_count": 3, "username": "davider", "is_followed": false}
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Metwit
|
3
|
+
describe Metag do
|
4
|
+
def metag
|
5
|
+
factory = RGeo::Cartesian.factory
|
6
|
+
|
7
|
+
options = {
|
8
|
+
:weather => {:status => :clear},
|
9
|
+
:position => factory.point(1,2),
|
10
|
+
}
|
11
|
+
@metag ||= Metag.new(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#weather_valid?" do
|
15
|
+
it "should return false when weather is nil" do
|
16
|
+
metag.weather = nil
|
17
|
+
metag.weather_valid?.should_not be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return false when weather[:status] is nil" do
|
21
|
+
metag.weather[:status] = nil
|
22
|
+
metag.weather_valid?.should_not be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return false with an unrecogonized weather status" do
|
26
|
+
metag.weather[:status] = :vola_tutto
|
27
|
+
metag.weather_valid?.should_not be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return true with a recognized weather status" do
|
31
|
+
metag.weather_valid?.should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return false when weather[:status] is not a symbol" do
|
35
|
+
metag.weather[:status] = 'sunny'
|
36
|
+
metag.weather_valid?.should_not be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#position_valid?" do
|
43
|
+
it "should return false when position is nil" do
|
44
|
+
metag.position = nil
|
45
|
+
metag.position_valid?.should_not be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return false when position is not a geographical point" do
|
49
|
+
gis = RGeo::Cartesian.factory
|
50
|
+
metag.position = gis.line(gis.point(1,2), gis.point(2,1))
|
51
|
+
metag.position_valid?.should_not be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return true when position is a Point" do
|
55
|
+
metag.position_valid?.should be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#valid?" do
|
62
|
+
it "should return true with a valid metag" do
|
63
|
+
metag.should be_valid
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return false with an invalid metag" do
|
67
|
+
metag.position = nil
|
68
|
+
metag.should_not be_valid
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
describe "::find" do
|
75
|
+
around do |example|
|
76
|
+
WebMock.disable_net_connect!
|
77
|
+
url = BASE_URL + '/metags/1234/'
|
78
|
+
WebMock.stub_http_request(:get, url).to_return(fixture("metag1234"))
|
79
|
+
example.run
|
80
|
+
WebMock.reset!
|
81
|
+
WebMock.allow_net_connect!
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return a Metag object" do
|
85
|
+
Metag.find("1234").should be_a Metag
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return a Metag with the id requested" do
|
89
|
+
id = "1234"
|
90
|
+
metag = Metag.find(id)
|
91
|
+
metag.id.should eq id
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have all the guaranteed fields" do
|
95
|
+
metag = Metag.find("1234")
|
96
|
+
metag.id.should_not be_nil
|
97
|
+
metag.timestamp.should_not be_nil
|
98
|
+
metag.weather.should_not be_nil
|
99
|
+
metag.position.should_not be_nil
|
100
|
+
metag.user.should_not be_nil
|
101
|
+
metag.replies_count.should_not be_nil
|
102
|
+
metag.thanks_count.should_not be_nil
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#to_json" do
|
108
|
+
it "should encode GeoJSON correctly" do
|
109
|
+
json_metag = JSON.parse(metag.to_json)
|
110
|
+
new_metag = Metag.new(:position => RGeo::GeoJSON.decode(json_metag['geo']))
|
111
|
+
new_metag.position_valid?.should be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should encode weather status correctly" do
|
115
|
+
json_metag = JSON.parse(metag.to_json)
|
116
|
+
new_metag = Metag.new(:weather => {:status => json_metag['weather']['status'].gsub(/ /, '_').to_sym})
|
117
|
+
new_metag.weather_valid?.should be_true
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#create!" do
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "::in_rect" do
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "::from_json" do
|
129
|
+
around do |example|
|
130
|
+
WebMock.disable_net_connect!
|
131
|
+
url = BASE_URL + '/metags/1234/'
|
132
|
+
WebMock.stub_http_request(:get, url).to_return(fixture("metag1234"))
|
133
|
+
example.run
|
134
|
+
WebMock.reset!
|
135
|
+
WebMock.allow_net_connect!
|
136
|
+
end
|
137
|
+
|
138
|
+
def metag
|
139
|
+
url = BASE_URL + '/metags/1234/'
|
140
|
+
response = HTTParty.get(url)
|
141
|
+
Metag.from_json(response)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return a metag with String id" do
|
145
|
+
metag.id.should be_a String
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should return a metag with Time timestamp" do
|
149
|
+
metag.timestamp.should be_a Time
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return a metag with RGeo::Feature::Point position" do
|
153
|
+
metag.position_valid?.should be_true
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should return a metag with valid weather" do
|
157
|
+
metag.weather_valid?.should be_true
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should return a metag with User user" do
|
161
|
+
metag.user.should be_a User
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should return a metag with Fixnum replies_count" do
|
165
|
+
metag.replies_count.should be_a Fixnum
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should return a metag with Fixnum thanks_count" do
|
169
|
+
metag.thanks_count.should be_a Fixnum
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Metwit
|
3
|
+
describe User do
|
4
|
+
|
5
|
+
describe "::find" do
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
WebMock.disable_net_connect!
|
9
|
+
url = BASE_URL + '/users/6576/'
|
10
|
+
WebMock.stub_http_request(:get, url).to_return(fixture("user6576"))
|
11
|
+
example.run
|
12
|
+
WebMock.reset!
|
13
|
+
WebMock.allow_net_connect!
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a User object" do
|
17
|
+
User.find("6576").should be_a User
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return a User with the id requested" do
|
21
|
+
id = "6576"
|
22
|
+
user = User.find(id)
|
23
|
+
user.id.should eq id
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have all the guaranteed fields" do
|
27
|
+
user = User.find("6576")
|
28
|
+
user.id.should_not be_nil
|
29
|
+
user.nickname.should_not be_nil
|
30
|
+
user.metags_count.should_not be_nil
|
31
|
+
user.today_metags_count.should_not be_nil
|
32
|
+
user.avatar.should_not be_nil
|
33
|
+
user.followed?.should_not
|
34
|
+
user.followers_count.should_not be_nil
|
35
|
+
user.following_count.should_not be_nil
|
36
|
+
user.facebook?.should_not be_nil
|
37
|
+
user.twitter?.should_not be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "::from_json" do
|
43
|
+
around do |example|
|
44
|
+
WebMock.disable_net_connect!
|
45
|
+
url = BASE_URL + '/users/6576/'
|
46
|
+
WebMock.stub_http_request(:get, url).to_return(fixture("user6576"))
|
47
|
+
example.run
|
48
|
+
WebMock.reset!
|
49
|
+
WebMock.allow_net_connect!
|
50
|
+
end
|
51
|
+
|
52
|
+
def user
|
53
|
+
url = BASE_URL + '/users/6576/'
|
54
|
+
response = HTTParty.get(url)
|
55
|
+
User.from_json(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return a user with String id" do
|
59
|
+
user.id.should be_a String
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return a user with String nickname" do
|
63
|
+
user.nickname.should be_a String
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return a user with Fixnum metags_count" do
|
67
|
+
user.metags_count.should be_a Fixnum
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return a user with Fixnum today_metags_count" do
|
71
|
+
user.today_metags_count.should be_a Fixnum
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return a user with URI avatar" do
|
75
|
+
user.avatar.should be_a URI
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return a user with Boolean followed" do
|
79
|
+
user.followed?.should be_boolean
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return a user with Fixnum followers_count" do
|
83
|
+
user.followers_count.should be_a Fixnum
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
it "should return a user with Fixnum following_count" do
|
88
|
+
user.following_count.should be_a Fixnum
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return a user with Boolean facebook" do
|
92
|
+
user.facebook?.should be_boolean
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return a user with Boolean twitter" do
|
96
|
+
user.twitter?.should be_boolean
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'metwit'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
RSpec::Matchers.define :be_boolean do
|
8
|
+
match do |value|
|
9
|
+
value.is_a?(TrueClass) or value.is_a?(FalseClass)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
WebMock.allow_net_connect!
|
15
|
+
|
16
|
+
def fixture(filename)
|
17
|
+
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}"))
|
18
|
+
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.
|
4
|
+
version: 0.0.2
|
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: 2012-07-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
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: rgeo-geojson
|
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: Ruby SDK for Metwit public APIs
|
15
47
|
email:
|
16
48
|
- sim@me.com
|
@@ -19,13 +51,23 @@ extensions: []
|
|
19
51
|
extra_rdoc_files: []
|
20
52
|
files:
|
21
53
|
- .gitignore
|
54
|
+
- .yardopts
|
22
55
|
- Gemfile
|
23
56
|
- LICENSE
|
24
57
|
- README.md
|
25
58
|
- Rakefile
|
26
59
|
- lib/metwit.rb
|
60
|
+
- lib/metwit/auth.rb
|
61
|
+
- lib/metwit/constants.rb
|
62
|
+
- lib/metwit/metag.rb
|
63
|
+
- lib/metwit/user.rb
|
27
64
|
- lib/metwit/version.rb
|
28
65
|
- metwit.gemspec
|
66
|
+
- spec/fixtures/metag1234
|
67
|
+
- spec/fixtures/user6576
|
68
|
+
- spec/metwit/metag_spec.rb
|
69
|
+
- spec/metwit/user_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
29
71
|
homepage: http://metwit.com
|
30
72
|
licenses: []
|
31
73
|
post_install_message:
|
@@ -50,5 +92,10 @@ rubygems_version: 1.8.23
|
|
50
92
|
signing_key:
|
51
93
|
specification_version: 3
|
52
94
|
summary: Ruby SDK for Metwit public APIs
|
53
|
-
test_files:
|
95
|
+
test_files:
|
96
|
+
- spec/fixtures/metag1234
|
97
|
+
- spec/fixtures/user6576
|
98
|
+
- spec/metwit/metag_spec.rb
|
99
|
+
- spec/metwit/user_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
54
101
|
has_rdoc:
|