api_object 0.0.1 → 0.2.0
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/LICENSE +2 -0
- data/README.md +13 -6
- data/lib/api_object/query.rb +8 -4
- data/lib/api_object/version.rb +1 -1
- data/lib/api_object.rb +63 -28
- data/test/data/bus/muni_F.xml +126 -0
- data/test/data/bus/muni_routes.xml +83 -0
- data/test/data/estimate/glen.xml +0 -146
- data/test/data/estimate/sixteenth.xml +0 -141
- data/test/data/estimate/twenty_fourth.xml +0 -128
- data/test/data/weather/mountain_view.xml +49 -0
- data/test/unit/api_object_test.rb +82 -8
- data/test/unit/load_from_xml.rb +22 -7
- data/test/unit/route.rb +76 -0
- data/test/unit/station.rb +11 -2
- data/test/unit/weather.rb +88 -0
- metadata +19 -14
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'api_object'
|
2
|
+
require_relative 'load_from_xml'
|
3
|
+
module TestObjects
|
4
|
+
|
5
|
+
module WeatherMethods
|
6
|
+
def to_s
|
7
|
+
inspect
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ForecastInfo < ActiveApi::ApiObject
|
12
|
+
include WeatherMethods
|
13
|
+
attr_reader :city, :current_date, :current_time
|
14
|
+
|
15
|
+
api_column :current_date, :forecast_date
|
16
|
+
api_column :current_time, :current_date_time
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
"#{@city} #{@current_time}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other_info)
|
23
|
+
return false if other_info.nil?
|
24
|
+
self.city == other_info.city
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class CurrentWeather < ActiveApi::ApiObject
|
30
|
+
include WeatherMethods
|
31
|
+
attr_reader :sky, :temp_f, :temp_c, :humidity, :wind
|
32
|
+
|
33
|
+
api_column :sky, :condition
|
34
|
+
api_column :wind, :wind_condition
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
"Today #{@temp_f}F (#{@temp_c}C), #{@sky}, #{@humidity}, #{@wind}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class WeatherForecast < ActiveApi::ApiObject
|
42
|
+
include WeatherMethods
|
43
|
+
attr_reader :day_of_week, :temp_low, :temp_high, :sky
|
44
|
+
|
45
|
+
api_column :temp_low, :low
|
46
|
+
api_column :temp_high, :high
|
47
|
+
api_column :sky, :condition
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
"#{@day_of_week} low #{@temp_low}, high #{@temp_high}, #{@sky}"
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class Weather < ActiveApi::ApiObject
|
57
|
+
extend LoadFromXML
|
58
|
+
include WeatherMethods
|
59
|
+
attr_reader :forecast_information, :current_conditions, :forecast_conditions
|
60
|
+
|
61
|
+
initialize_from_api :url => "http://www.google.com/ig/", :action => 'api', :data_tags => :data
|
62
|
+
|
63
|
+
api_association :forecast_information, :as => ForecastInfo
|
64
|
+
api_association :current_conditions, :as => CurrentWeather
|
65
|
+
api_association :forecast_conditions, :as => WeatherForecast
|
66
|
+
|
67
|
+
|
68
|
+
def inspect
|
69
|
+
"#{@forecast_information} \n\t#{@current_conditions} \n\t#{@forecast_conditions.instance_of?(Array) ? (@forecast_conditions.inject('') {|str, e| (str + e.inspect + "\n\t")}) : @forecast_conditions}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def ==(other_weather)
|
73
|
+
return false if other_weather.nil?
|
74
|
+
self.forecast_information == other_weather.forecast_information && self.current_conditions != nil && other_weather.current_conditions != nil && self.forecast_conditions.size == other_weather.forecast_conditions.size
|
75
|
+
end
|
76
|
+
|
77
|
+
class << self
|
78
|
+
alias_method :general_load_from_xml, :load_from_xml
|
79
|
+
|
80
|
+
def load_from_xml xml
|
81
|
+
general_load_from_xml(xml, 'xml_api_reply', 'weather')
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
16
|
-
requirement: &
|
16
|
+
requirement: &84182880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *84182880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &84182660 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *84182660
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &84182340 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *84182340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &84182020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *84182020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: nori
|
60
|
-
requirement: &
|
60
|
+
requirement: &84181690 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '1.1'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *84181690
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rest-client
|
71
|
-
requirement: &
|
71
|
+
requirement: &84181440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '1.6'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *84181440
|
80
80
|
description: An interface to load objects from external APIs provided in XML and JSON
|
81
81
|
formats
|
82
82
|
email:
|
@@ -94,12 +94,17 @@ files:
|
|
94
94
|
- lib/api_object/config_params.rb
|
95
95
|
- lib/api_object/query.rb
|
96
96
|
- lib/api_object/version.rb
|
97
|
+
- test/data/bus/muni_F.xml
|
98
|
+
- test/data/bus/muni_routes.xml
|
97
99
|
- test/data/estimate/glen.xml
|
98
100
|
- test/data/estimate/sixteenth.xml
|
99
101
|
- test/data/estimate/twenty_fourth.xml
|
102
|
+
- test/data/weather/mountain_view.xml
|
100
103
|
- test/unit/api_object_test.rb
|
101
104
|
- test/unit/load_from_xml.rb
|
105
|
+
- test/unit/route.rb
|
102
106
|
- test/unit/station.rb
|
107
|
+
- test/unit/weather.rb
|
103
108
|
homepage: https://github.com/tmoskun/api_object
|
104
109
|
licenses: []
|
105
110
|
post_install_message:
|