apis-is 1.0.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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +14 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +63 -0
  8. data/Rakefile +9 -0
  9. data/apis-is.gemspec +25 -0
  10. data/examples/bus_example.rb +27 -0
  11. data/examples/car_example.rb +27 -0
  12. data/examples/cinema_example.rb +32 -0
  13. data/examples/company_example.rb +23 -0
  14. data/examples/currency_example.rb +25 -0
  15. data/examples/cyclecounter_example.rb +20 -0
  16. data/examples/earthquake_example.rb +23 -0
  17. data/examples/flights_example.rb +25 -0
  18. data/examples/lottery_example.rb +23 -0
  19. data/examples/particulates_example.rb +21 -0
  20. data/examples/tv_example.rb +37 -0
  21. data/examples/weather_example.rb +34 -0
  22. data/lib/apis.rb +109 -0
  23. data/lib/apis/client.rb +30 -0
  24. data/lib/apis/endpoints/bus.rb +15 -0
  25. data/lib/apis/endpoints/cars.rb +14 -0
  26. data/lib/apis/endpoints/cinema.rb +22 -0
  27. data/lib/apis/endpoints/companies.rb +38 -0
  28. data/lib/apis/endpoints/currency.rb +27 -0
  29. data/lib/apis/endpoints/cyclecounter.rb +14 -0
  30. data/lib/apis/endpoints/earthquake.rb +13 -0
  31. data/lib/apis/endpoints/flights.rb +24 -0
  32. data/lib/apis/endpoints/lottery.rb +27 -0
  33. data/lib/apis/endpoints/particulates.rb +13 -0
  34. data/lib/apis/endpoints/tv.rb +69 -0
  35. data/lib/apis/endpoints/weather.rb +37 -0
  36. data/lib/apis/response/feed_parser.rb +16 -0
  37. data/lib/apis/version.rb +6 -0
  38. data/spec/fixtures/bus_all.yml +216 -0
  39. data/spec/fixtures/bus_selective.yml +82 -0
  40. data/spec/fixtures/car.yml +53 -0
  41. data/spec/fixtures/cinema_showtimes.yml +319 -0
  42. data/spec/fixtures/cinema_theaters.yml +192 -0
  43. data/spec/fixtures/companies_by_address.yml +141 -0
  44. data/spec/fixtures/companies_by_name.yml +84 -0
  45. data/spec/fixtures/companies_by_socialnumber.yml +50 -0
  46. data/spec/fixtures/companies_by_vsknr.yml +50 -0
  47. data/spec/fixtures/currency_arion.yml +83 -0
  48. data/spec/fixtures/currency_lb.yml +104 -0
  49. data/spec/fixtures/currency_m5.yml +77 -0
  50. data/spec/fixtures/cyclecounter.yml +50 -0
  51. data/spec/fixtures/earthquake.yml +1311 -0
  52. data/spec/fixtures/flights_arrivals.yml +269 -0
  53. data/spec/fixtures/flights_departure.yml +247 -0
  54. data/spec/fixtures/lottery_eurojackpot.yml +57 -0
  55. data/spec/fixtures/lottery_lotto.yml +57 -0
  56. data/spec/fixtures/lottery_vikingalotto.yml +57 -0
  57. data/spec/fixtures/particulates.yml +49 -0
  58. data/spec/fixtures/tv_ruv.yml +380 -0
  59. data/spec/fixtures/tv_ruvithrottir.yml +47 -0
  60. data/spec/fixtures/tv_skjar1.yml +317 -0
  61. data/spec/fixtures/tv_stod2.yml +491 -0
  62. data/spec/fixtures/tv_stod2bio.yml +217 -0
  63. data/spec/fixtures/tv_stod2gull.yml +284 -0
  64. data/spec/fixtures/tv_stod2sport.yml +105 -0
  65. data/spec/fixtures/tv_stod2sport2.yml +118 -0
  66. data/spec/fixtures/tv_stod3.yml +301 -0
  67. data/spec/fixtures/weather_forecast.yml +215 -0
  68. data/spec/fixtures/weather_observations.yml +215 -0
  69. data/spec/fixtures/weather_texts.yml +79 -0
  70. data/spec/helper.rb +18 -0
  71. data/spec/specs/bus_spec.rb +17 -0
  72. data/spec/specs/car_spec.rb +10 -0
  73. data/spec/specs/cinema_spec.rb +19 -0
  74. data/spec/specs/company_spec.rb +40 -0
  75. data/spec/specs/currency_spec.rb +30 -0
  76. data/spec/specs/cyclecounter_spec.rb +10 -0
  77. data/spec/specs/earthquake_spec.rb +10 -0
  78. data/spec/specs/flights_spec.rb +22 -0
  79. data/spec/specs/lottery_spec.rb +30 -0
  80. data/spec/specs/particulates_spec.rb +10 -0
  81. data/spec/specs/tv_spec.rb +84 -0
  82. data/spec/specs/weather_spec.rb +31 -0
  83. metadata +205 -0
@@ -0,0 +1,37 @@
1
+ require 'apis'
2
+
3
+ # Possible Tv calls
4
+ #
5
+ # Apis.tv.ruv <- Fetch tv schedule for RUV
6
+ # Apis.tv.ruvithrottir <- Fetch tv schedule for RUV Ithrottir
7
+ # Apis.tv.stod2 <- Fetch tv schedule for Stod 2
8
+ # Apis.tv.stod2sport <- Fetch tv schedule for Stod 2 Sport
9
+ # Apis.tv.stod2sport2 <- Fetch tv schedule for Stod 2 Sport 2
10
+ # Apis.tv.stod2gull <- Fetch tv schedule for Stod 2 Gull
11
+ # Apis.tv.stod2bio <- Fetch tv schedule for Stod 2 Bio
12
+ # Apis.tv.stod3 <- Fetch tv schedule for Stod 3
13
+ # Apis.tv.skjar1 <- Fetch tv schedule for Skjar 1
14
+
15
+ response = Apis.tv.ruv
16
+
17
+ # prints out all results
18
+ puts response[:results]
19
+
20
+ # Result:
21
+ # [
22
+ # {
23
+ # title: String,
24
+ # originalTitle: String,
25
+ # duration: String,
26
+ # description: String,
27
+ # shortDescription: String,
28
+ # live: Boolean,
29
+ # premier: Boolean,
30
+ # startTime: String,
31
+ # aspectRatio: String,
32
+ # series: {
33
+ # episode: String,
34
+ # series: String
35
+ # }
36
+ # }
37
+ # ]
@@ -0,0 +1,34 @@
1
+ require 'apis'
2
+
3
+ # Possible Weather calls
4
+ #
5
+ # Apis.weather.texts(types)
6
+ # Apis.weather.observations(stations, lang = 'is', time = '1h', anytime = '0')
7
+ # Apis.weather.forecasts(stations, lang = 'is')
8
+
9
+ Apis.weather.observations([361])
10
+
11
+ # prints out all results
12
+ puts response[:results]
13
+
14
+ # Result:
15
+ # [
16
+ # {
17
+ # name: String,
18
+ # atime: String,
19
+ # err: String,
20
+ # link: String,
21
+ # forecast: [
22
+ # {
23
+ # ftime: String,
24
+ # F: String,
25
+ # D: String,
26
+ # T: String,
27
+ # W: String,
28
+ # N: String,
29
+ # TD: String,
30
+ # R: String
31
+ # }
32
+ # ]
33
+ # }
34
+ # ]
@@ -0,0 +1,109 @@
1
+ require 'apis/client'
2
+ require 'apis/endpoints/tv'
3
+ require 'apis/endpoints/bus'
4
+ require 'apis/endpoints/cars'
5
+ require 'apis/endpoints/cinema'
6
+ require 'apis/endpoints/flights'
7
+ require 'apis/endpoints/lottery'
8
+ require 'apis/endpoints/weather'
9
+ require 'apis/endpoints/currency'
10
+ require 'apis/endpoints/companies'
11
+ require 'apis/endpoints/earthquake'
12
+ require 'apis/endpoints/cyclecounter'
13
+ require 'apis/endpoints/particulates'
14
+
15
+ # Ruby wrapper for the apis.is API
16
+ module Apis
17
+ class << self
18
+ # API Client
19
+ #
20
+ # @return [Apis::Client] API wrapper
21
+ def client
22
+ Apis::Client.new
23
+ end
24
+
25
+ # API CycleCounter
26
+ #
27
+ # @return [Apis::CycleCounter] API wrapper
28
+ def cyclecounter
29
+ Apis::CycleCounter.new.cyclecounter
30
+ end
31
+
32
+ # API Earthquake
33
+ #
34
+ # @return [Apis::Earthquake] API wrapper
35
+ def earthquake
36
+ Apis::Earthquake.new.earthquake
37
+ end
38
+
39
+ # API Currency
40
+ #
41
+ # @return [Apis::Currency] API wrapper
42
+ def currency
43
+ Apis::Currency.new
44
+ end
45
+
46
+ # API Cinema
47
+ #
48
+ # @return [Apis::Cinema] API wrapper
49
+ def cinema
50
+ Apis::Cinema.new
51
+ end
52
+
53
+ # API Particulates
54
+ #
55
+ # @return [Apis::Particulates] API wrapper
56
+ def particulates
57
+ Apis::Particulates.new.particulates
58
+ end
59
+
60
+ # API Lottery
61
+ #
62
+ # @return [Apis::Lottery] API wrapper
63
+ def lottery
64
+ Apis::Lottery.new
65
+ end
66
+
67
+ # API Busses
68
+ #
69
+ # @return [Apis::Busses] API wrapper
70
+ def busses(params = [])
71
+ Apis::Busses.new.realtime(params)
72
+ end
73
+
74
+ # API Cars
75
+ #
76
+ # @return [Apis::Cars] API wrapper
77
+ def car(number)
78
+ Apis::Cars.new.car(number)
79
+ end
80
+
81
+ # API Companies
82
+ #
83
+ # @return [Apis::Companies] API wrapper
84
+ def companies
85
+ Apis::Companies.new
86
+ end
87
+
88
+ # API Tv
89
+ #
90
+ # @return [Apis::Tv] API wrapper
91
+ def tv
92
+ Apis::Tv.new
93
+ end
94
+
95
+ # API Flights
96
+ #
97
+ # @return [Apis::Flights] API wrapper
98
+ def flights
99
+ Apis::Flights.new
100
+ end
101
+
102
+ # API Weather
103
+ #
104
+ # @return [Apis::Weather] API wrapper
105
+ def weather
106
+ Apis::Weather.new
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,30 @@
1
+ require 'faraday'
2
+ require 'apis/response/feed_parser'
3
+
4
+ module Apis
5
+ # Client for the Apis API
6
+ #
7
+ # @see http://docs.apis.is/
8
+ class Client
9
+ # Apis.is url prefix
10
+ URL_PREFIX = 'http://apis.is'
11
+
12
+ # Apis.is Farafay Connection
13
+ #
14
+ # @return [Faraday::Connection]
15
+ def agent
16
+ Faraday.new(URL_PREFIX) do |fara|
17
+ fara.use Apis::Response::FeedParser
18
+ fara.adapter Faraday.default_adapter
19
+ end
20
+ end
21
+
22
+ # Make a HTTP GET request
23
+ #
24
+ # @param url [String] The path, relative to the url prefix
25
+ # @return [Faraday::Response]
26
+ def get(path)
27
+ agent.get(path).body
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch busses
5
+ class Busses
6
+ # Real-time location of busses.
7
+ # Results are only shown for active busses.
8
+ #
9
+ # @param busses [Array] List of requested busses (optional)
10
+ # @return [Faraday::Response] Api result.
11
+ def realtime(busses)
12
+ Apis.client.get("/bus/realtime?busses=#{busses.join(',')}")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch cars
5
+ class Cars
6
+ # Search the icelandic vehicle registry
7
+ #
8
+ # @param number [String] Car number (required)
9
+ # @return [Faraday::Response] Api result.
10
+ def car(number)
11
+ Apis.client.get("/car?number=#{number}")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch cinema
5
+ class Cinema
6
+ # Get a list of showtimes in icelandic movie theaters;
7
+ # sort by movies
8
+ #
9
+ # @return [Faraday::Response] Api result.
10
+ def showtimes
11
+ Apis.client.get('/cinema')
12
+ end
13
+
14
+ # Get a list of showtimes in icelandic movie theaters;
15
+ # sort by theater
16
+ #
17
+ # @return [Faraday::Response] Api result.
18
+ def theaters
19
+ Apis.client.get('/cinema/theaters')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch companies
5
+ class Companies
6
+ # Search the icelandic company registry by name
7
+ #
8
+ # @param name [String] company name (required)
9
+ # @return [Faraday::Response] Api result.
10
+ def by_name(name)
11
+ Apis.client.get("/company?name=#{name}")
12
+ end
13
+
14
+ # Search the icelandic company registry by address
15
+ #
16
+ # @param address [String] company address (required)
17
+ # @return [Faraday::Response] Api result.
18
+ def by_address(address)
19
+ Apis.client.get("/company?address=#{address}")
20
+ end
21
+
22
+ # Search the icelandic company registry by social number
23
+ #
24
+ # @param socialnumber [String] company socialnumber (required)
25
+ # @return [Faraday::Response] Api result.
26
+ def by_sn(socialnumber)
27
+ Apis.client.get("/company?socialnumber=#{socialnumber}")
28
+ end
29
+
30
+ # Search the icelandic company registry by vsk number
31
+ #
32
+ # @param vsknr [String] company vsknumer (required)
33
+ # @return [Faraday::Response] Api result.
34
+ def by_vsknr(vsknr)
35
+ Apis.client.get("/company?vsknr=#{vsknr}")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch currency
5
+ class Currency
6
+ # Get currency data from Arion
7
+ #
8
+ # @return [Faraday::Response] Api result.
9
+ def arion
10
+ Apis.client.get('/currency/arion')
11
+ end
12
+
13
+ # Get currency data from m5
14
+ #
15
+ # @return [Faraday::Response] Api result.
16
+ def m5
17
+ Apis.client.get('/currency/m5')
18
+ end
19
+
20
+ # Get currency data from Landsbankinn
21
+ #
22
+ # @return [Faraday::Response] Api result.
23
+ def lb
24
+ Apis.client.get('/currency/lb')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch cyclecounter
5
+ class CycleCounter
6
+ # Get current status of bicycle counters in Iceland,
7
+ # currently only one located by Sudurlandsbraut in Reykjavik.
8
+ #
9
+ # @return [Faraday::Response] Api result.
10
+ def cyclecounter
11
+ Apis.client.get('/cyclecounter')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch earthquake
5
+ class Earthquake
6
+ # Get earthquake monitoring data for the last 48 hours.
7
+ #
8
+ # @return [Faraday::Response] Api result.
9
+ def earthquake
10
+ Apis.client.get('/earthquake/is')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch flights
5
+ class Flights
6
+ # Get a list of all international flights departure
7
+ # at Keflavik Airport today.
8
+ #
9
+ # @param lang [String] result language (optional)
10
+ # @return [Faraday::Response] Api result.
11
+ def departure(lang = 'is')
12
+ Apis.client.get("/flight?type=departures&language=#{lang}")
13
+ end
14
+
15
+ # Get a list of all international flights arriving
16
+ # at Keflavik Airport today.
17
+ #
18
+ # @param lang [String] result language (optional)
19
+ # @return [Faraday::Response] Api result.
20
+ def arrivals(lang = 'is')
21
+ Apis.client.get("/flight?type=arrivals&language=#{lang}")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch lottery
5
+ class Lottery
6
+ # Get the most recent numbers for the icelandic lottery.
7
+ #
8
+ # @return [Faraday::Response] Api result.
9
+ def lotto
10
+ Apis.client.get('/lottery')
11
+ end
12
+
13
+ # Get the most recent numbers for the Vikingalotto.
14
+ #
15
+ # @return [Faraday::Response] Api result.
16
+ def vikingalotto
17
+ Apis.client.get('/lottery/vikingalotto')
18
+ end
19
+
20
+ # Get the most recent numbers for the Eurojackpot.
21
+ #
22
+ # @return [Faraday::Response] Api result.
23
+ def eurojackpot
24
+ Apis.client.get('/lottery/eurojackpot')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch particulates
5
+ class Particulates
6
+ # Get current status of particulates in Reykjavik City
7
+ #
8
+ # @return [Faraday::Response] Api result.
9
+ def particulates
10
+ Apis.client.get('/particulates')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,69 @@
1
+ require 'apis/client'
2
+
3
+ module Apis
4
+ # Class to fetch tv
5
+ class Tv
6
+ # Get today's schedule from RUV
7
+ #
8
+ # @return [Faraday::Response] Api result.
9
+ def ruv
10
+ Apis.client.get('/tv/ruv')
11
+ end
12
+
13
+ # Get today's schedule from RUV ITHROTTIR
14
+ #
15
+ # @return [Faraday::Response] Api result.
16
+ def ruvithrottir
17
+ Apis.client.get('/tv/ruvithrottir')
18
+ end
19
+
20
+ # Get today's schedule from Stod 2
21
+ #
22
+ # @return [Faraday::Response] Api result.
23
+ def stod2
24
+ Apis.client.get('/tv/stod2')
25
+ end
26
+
27
+ # Get today's schedule from Stod 2 sport
28
+ #
29
+ # @return [Faraday::Response] Api result.
30
+ def stod2sport
31
+ Apis.client.get('/tv/stod2sport')
32
+ end
33
+
34
+ # Get today's schedule from Stod 2 sport 2
35
+ #
36
+ # @return [Faraday::Response] Api result.
37
+ def stod2sport2
38
+ Apis.client.get('/tv/stod2sport2')
39
+ end
40
+
41
+ # Get today's schedule from Stod 2 gull
42
+ #
43
+ # @return [Faraday::Response] Api result.
44
+ def stod2gull
45
+ Apis.client.get('/tv/stod2gull')
46
+ end
47
+
48
+ # Get today's schedule from Stod 2
49
+ #
50
+ # @return [Faraday::Response] Api result.
51
+ def stod2bio
52
+ Apis.client.get('/tv/stod2bio')
53
+ end
54
+
55
+ # Get today's schedule from Stod 3
56
+ #
57
+ # @return [Faraday::Response] Api result.
58
+ def stod3
59
+ Apis.client.get('/tv/stod3')
60
+ end
61
+
62
+ # Get today's schedule from Skjar 1
63
+ #
64
+ # @return [Faraday::Response] Api result.
65
+ def skjar1
66
+ Apis.client.get('/tv/skjar1')
67
+ end
68
+ end
69
+ end