parkeon 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in parkeon.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ryan Closner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Parkeon
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'parkeon'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install parkeon
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ require "nokogiri"
2
+ require "virtus"
3
+
4
+ require "parkeon/builder"
5
+ require "parkeon/client"
6
+ require "parkeon/config"
7
+ require "parkeon/gateway"
8
+ require "parkeon/response"
9
+ require "parkeon/session"
10
+ require "parkeon/ticket"
11
+ require "parkeon/version"
12
+
13
+ module Parkeon
14
+ end
@@ -0,0 +1,34 @@
1
+ module Parkeon
2
+ class Builder
3
+
4
+ def self.build(method_name, &block)
5
+ new(method_name).build(&block)
6
+ end
7
+
8
+ def initialize(method_name)
9
+ @method_name = method_name
10
+ end
11
+
12
+ def build(&block)
13
+ Nokogiri::XML::Builder.new do |xml|
14
+ xml.methodCall {
15
+ xml.methodName method_name
16
+ xml.params {
17
+ xml.param {
18
+ xml.value {
19
+ xml.struct {
20
+ block.call(xml)
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ end.to_xml
27
+ end
28
+
29
+ private
30
+
31
+ attr_accessor :method_name
32
+
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require "net/http"
2
+ require "uri"
3
+
4
+ module Parkeon
5
+ class Client
6
+
7
+ def self.post(*args)
8
+ new(*args).post
9
+ end
10
+
11
+ def initialize(body)
12
+ @body = body
13
+ end
14
+
15
+ def post
16
+ request = Net::HTTP::Post.new(uri.request_uri)
17
+ request.body = body
18
+ Response.new https.request(request)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :body
24
+
25
+ def https
26
+ Net::HTTP.new(uri.host, uri.port).tap { |client| client.use_ssl = true }
27
+ end
28
+
29
+ def uri
30
+ URI(endpoint)
31
+ end
32
+
33
+ def endpoint
34
+ Config.endpoint
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ module Parkeon
2
+ class Config
3
+ class << self
4
+ attr_accessor :endpoint, :requester, :version, :service
5
+
6
+ def configure(&block)
7
+ yield self if block_given?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ module Parkeon
2
+ class Gateway
3
+
4
+ def self.define_service(method_name, verb)
5
+ self.class.instance_eval do
6
+ define_method(method_name) do |&block|
7
+ Client.send(verb, Builder.build(method_name, &block))
8
+ end
9
+ end
10
+ end
11
+
12
+ define_service :create_session, :post
13
+ define_service :invoke_session, :post
14
+ define_service :terminate_session, :post
15
+
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ module Parkeon
2
+ class Response
3
+
4
+ SUCCESS_CODE = "200".freeze
5
+
6
+ def initialize(response)
7
+ @response = response
8
+ end
9
+
10
+ def find(selector)
11
+ xml.at_css(selector)
12
+ end
13
+ alias :at_css :find
14
+
15
+ def all(selector)
16
+ xml.css(selector)
17
+ end
18
+ alias :css :all
19
+
20
+ def code
21
+ response.code
22
+ end
23
+
24
+ def success?
25
+ code == SUCCESS_CODE
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :response
31
+
32
+ def body
33
+ response.body
34
+ end
35
+
36
+ def xml
37
+ Nokogiri::XML(body)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,77 @@
1
+ module Parkeon
2
+ class Session
3
+
4
+ def self.create
5
+ response =
6
+ Gateway.create_session do |xml|
7
+ xml.member {
8
+ xml.name "requester"
9
+ xml.value {
10
+ xml.string Config.requester
11
+ }
12
+ }
13
+ xml.member {
14
+ xml.name "service"
15
+ xml.value {
16
+ xml.string Config.service
17
+ }
18
+ }
19
+ xml.member {
20
+ xml.name "version"
21
+ xml.value {
22
+ xml.i4 Config.version
23
+ }
24
+ }
25
+ end
26
+
27
+ new( response.find("member value i4").text ) if response.success?
28
+ end
29
+
30
+ def initialize(session_id)
31
+ @session_id = session_id
32
+ end
33
+
34
+ def invoke(method, &block)
35
+ Gateway.invoke_session do |xml|
36
+ xml.member {
37
+ xml.name "session_id"
38
+ xml.value {
39
+ xml.i4 session_id
40
+ }
41
+ }
42
+
43
+ xml.member {
44
+ xml.name "method"
45
+ xml.value {
46
+ xml.string method
47
+ }
48
+ }
49
+
50
+ xml.member {
51
+ xml.name "parameters"
52
+ xml.value {
53
+ xml.struct {
54
+ block.call(xml)
55
+ }
56
+ }
57
+ }
58
+ end
59
+ end
60
+
61
+ def terminate
62
+ Gateway.terminate_session do |xml|
63
+ xml.member {
64
+ xml.name "session_id"
65
+ xml.value {
66
+ xml.i4 session_id
67
+ }
68
+ }
69
+ end
70
+ end
71
+
72
+ private
73
+
74
+ attr_reader :session_id
75
+
76
+ end
77
+ end
@@ -0,0 +1,49 @@
1
+ module Parkeon
2
+ class Ticket
3
+
4
+ # INCLUSIONS
5
+
6
+ include Virtus
7
+
8
+ # CONSTANTS
9
+
10
+ BASE_SELECTOR = "member value array struct"
11
+ ATTR_SELECTOR = "member"
12
+ ATTR_NAME_SELECTOR = "name"
13
+ ATTR_VALUE_SELECTOR = "value"
14
+
15
+ # ATTRIBUTES
16
+
17
+ attribute :id, Integer
18
+ attribute :zone, Integer
19
+ attribute :user_type, Integer
20
+ attribute :plate, String
21
+ attribute :utc_start_time, DateTime
22
+ attribute :utc_end_time, DateTime
23
+
24
+ # CLASS METHODS
25
+
26
+ def self.all
27
+ get_tickets.css(BASE_SELECTOR).map {|node| from_node(node) }
28
+ end
29
+
30
+ def self.from_node(node)
31
+ attributes = {}
32
+
33
+ node.css(ATTR_SELECTOR).each do |member|
34
+ key = member.at_css(ATTR_NAME_SELECTOR)
35
+ value = member.at_css(ATTR_VALUE_SELECTOR)
36
+ attributes[key] = value
37
+ end
38
+
39
+ new(attributes)
40
+ end
41
+
42
+ private
43
+
44
+ def self.get_tickets
45
+ Session.create.invoke("get_tickets") {}
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Parkeon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'parkeon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "parkeon"
8
+ spec.version = Parkeon::VERSION
9
+ spec.authors = ["Ryan Closner"]
10
+ spec.email = ["ryan@ryanclosner.com"]
11
+ spec.description = %q{A Ruby wrapper to access the Parkeon parking meter API}
12
+ spec.summary = %q{A Ruby wrapper to access the Parkeon parking meter API}
13
+ spec.homepage = "https://github.com/rclosner/parkeon"
14
+ spec.license = "MIT"
15
+
16
+ runtime_dependencies = {
17
+ "nokogiri" => "~> 1.6.0",
18
+ "virtus" => "~> 0.5.5"
19
+ }
20
+
21
+ runtime_dependencies.each {|lib, version| spec.add_runtime_dependency lib, version }
22
+
23
+ development_dependencies = {
24
+ "bundler" => "~> 1.3.5",
25
+ "rake" => "~> 10.0.4"
26
+ }
27
+
28
+ development_dependencies.each {|lib, version| spec.add_development_dependency lib, version }
29
+
30
+ spec.files = `git ls-files`.split($/)
31
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
32
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
33
+ spec.require_paths = ["lib"]
34
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parkeon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Closner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.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: 1.6.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: virtus
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.5.5
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.5.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.5
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.5
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 10.0.4
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 10.0.4
78
+ description: A Ruby wrapper to access the Parkeon parking meter API
79
+ email:
80
+ - ryan@ryanclosner.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - lib/parkeon.rb
91
+ - lib/parkeon/builder.rb
92
+ - lib/parkeon/client.rb
93
+ - lib/parkeon/config.rb
94
+ - lib/parkeon/gateway.rb
95
+ - lib/parkeon/response.rb
96
+ - lib/parkeon/session.rb
97
+ - lib/parkeon/ticket.rb
98
+ - lib/parkeon/version.rb
99
+ - parkeon.gemspec
100
+ homepage: https://github.com/rclosner/parkeon
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.23
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: A Ruby wrapper to access the Parkeon parking meter API
125
+ test_files: []
126
+ has_rdoc: