streetline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23cb05a35e169750464dea1f58f1705259707c2a
4
+ data.tar.gz: 545385bbf6a01c09247f29ef536bce5b48f06522
5
+ SHA512:
6
+ metadata.gz: f6ecf484472c7b7bbb25150de3d5e168507e050d5f9bf2aaae7a5cb30a9c572d6734f25565c2049f2ecf1c242c9303f19ad5ebf7313d293b159989f94d6d87fb
7
+ data.tar.gz: db48f8e4ae421107c354965c3373a8e93cfabf4d6eee1de753bf88aa0640ae3514e0fe2b87b0491b1bf0247f9034f3fd7bf36429d40d29b2ba052b49dd5b7d2d
@@ -0,0 +1,16 @@
1
+ require 'active_support/core_ext'
2
+
3
+ require 'streetline/configuration'
4
+ require 'streetline/client'
5
+
6
+ module Streetline
7
+ extend Configuration
8
+
9
+ # Alias for Streetline::Client.new
10
+ #
11
+ # @return [Streetline::Client]
12
+ def new(options = {})
13
+ Streetline::Client.new(options)
14
+ end
15
+ module_function :new
16
+ end
@@ -0,0 +1,13 @@
1
+ module Streetline
2
+ module API
3
+ module Parking
4
+
5
+ # @param options [Hash]
6
+ # @return [Array]
7
+ def destinations(options = {})
8
+ response = get("/parkerdata/v1/ParkingDestinations.json", options)
9
+ response["ParkingDestinations"]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'streetline/connection'
2
+ require 'streetline/request'
3
+ require 'streetline/api/parking'
4
+
5
+ module Streetline
6
+ class Client
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+
9
+ # @param options [Hash]
10
+ def initialize(options = {})
11
+ options = Streetline.options.merge(options)
12
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
13
+ send("#{key}=", options[key])
14
+ end
15
+ end
16
+
17
+ include Streetline::Connection
18
+ include Streetline::Request
19
+ include Streetline::API::Parking
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require 'streetline/version'
2
+
3
+ module Streetline
4
+ module Configuration
5
+ VALID_OPTIONS_KEYS = [:api_endpoint, :api_token, :user_agent].freeze
6
+
7
+ DEFAULT_API_ENDPOINT = "https://api.streetline.com"
8
+ DEFAULT_API_TOKEN = nil
9
+ DEFAULT_USER_AGENT = "Streetline Ruby Gem #{Streetline::VERSION}".freeze
10
+
11
+ attr_accessor *VALID_OPTIONS_KEYS
12
+
13
+ def self.extended(base)
14
+ base.reset!
15
+ end
16
+
17
+ # Convenience method to allow configuration options to be set in a block
18
+ def configure
19
+ yield self
20
+ end
21
+
22
+ def options
23
+ Hash[ * VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten ]
24
+ end
25
+
26
+ def reset!
27
+ self.api_endpoint = DEFAULT_API_ENDPOINT
28
+ self.api_token = DEFAULT_API_TOKEN
29
+ self.user_agent = DEFAULT_USER_AGENT
30
+
31
+ return true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Streetline
5
+ module Connection
6
+
7
+ # Instantiate a Faraday::Connection
8
+ # @private
9
+ private
10
+
11
+ # Returns a Faraday::Connection object
12
+ #
13
+ # @param options [Hash]
14
+ # @return [Faraday::Connection]
15
+ def connection(options = {})
16
+ options = options.reverse_merge(url: Streetline.api_endpoint)
17
+
18
+ connection = Faraday.new(options) do |c|
19
+ c.request :json
20
+
21
+ c.response :json, content_type: /\bjson$/
22
+
23
+ # raise exceptions on 40x, 50x responses
24
+ c.use Faraday::Response::RaiseError
25
+
26
+ c.adapter Faraday.default_adapter
27
+ end
28
+
29
+ connection.headers[:user_agent] = Streetline.user_agent
30
+
31
+ connection
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,33 @@
1
+ module Streetline
2
+ module Request
3
+
4
+ # Performs a HTTP Get request
5
+ #
6
+ # @param path [String]
7
+ # @param params [Hash]
8
+ def get(path, params = {})
9
+ request(:get, path, params)
10
+ end
11
+
12
+
13
+ private
14
+
15
+ # Returns a Faraday::Response object
16
+ #
17
+ # @param method [Symbol]
18
+ # @param path [String]
19
+ # @param params [Hash]
20
+ # @return [Faraday::Response]
21
+ def request(method, path, params = {})
22
+ raise ArgumentError, ("Please configure Streetline.api_token first") unless api_token.present?
23
+
24
+ params = params.reverse_merge('Key' => api_token)
25
+
26
+ response = connection.send(method) do |request|
27
+ request.url(path, params)
28
+ end
29
+
30
+ response.body
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Streetline
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: streetline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Philippe Dionne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.14
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.14
55
+ description: Ruby client for the Streetline API
56
+ email:
57
+ - dionne.phil@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/streetline.rb
63
+ - lib/streetline/api/parking.rb
64
+ - lib/streetline/client.rb
65
+ - lib/streetline/configuration.rb
66
+ - lib/streetline/connection.rb
67
+ - lib/streetline/request.rb
68
+ - lib/streetline/version.rb
69
+ homepage: https://github.com/phildionne/streetline
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project: "[none]"
89
+ rubygems_version: 2.2.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Ruby client for the Streetline API
93
+ test_files: []