ruberto 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c0eb5e9105b9ab444063ce36009f1a0a94a9a711958383c7c9bccd09397d3aa2
4
+ data.tar.gz: b0fa20dcb59ec061d57348d17ba303f358ead9ed2c8fb0b5f8741cd40bc648e8
5
+ SHA512:
6
+ metadata.gz: cab5c5cc5636ae2e6530111b08e45ba75ddac4992fb05045c4eb065c4b0bf6a844cfc2595434fbf6bbafe8371de7716188a840cbb4fd1a0021b4944da84a7f92
7
+ data.tar.gz: e2cd17a2ed445775bd8eb3f5dde7af28fcdc86d4cbd52bd7ccefbf2e41a30280555d0aed71333dd1af58182007f0cb09c41fd44b4f130747a954417410c22963
data/.env ADDED
@@ -0,0 +1,2 @@
1
+ UBER_CLIENT_SECRET=filbWhy7jAipeJiEGSLAgQLZhExtIDuOckuHg0Lk
2
+ UBER_ACCESS_TOKEN=IA.VUNmGAAAAAAAEgASAAAABwAIAAwAAAAAAAAAEgAAAAAAAAGsAAAAFAAAAAAADgAQAAQAAAAIAAwAAAAOAAAAgAAAABwAAAAEAAAAEAAAAAbUBseRZ-zrxffnw7VfEs5cAAAAJ7IQyS63IIlNvTxZmfjz8FpA7nihseEOUCmyRrQnWnTTWZjBfEzqgXh3or6WIwP4yfCKpzwTQArvBjORRgIsCItPvcMz7OA6sCaaxtdqMSq32WNyWkASN8I__p4MAAAAx7RxMqa8FBTo01HRJAAAAGIwZDg1ODAzLTM4YTAtNDJiMy04MDZlLTdhNGNmOGUxOTZlZQ
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+ NewCops: disable
4
+ TargetRubyVersion: 3.0
5
+
6
+ Style/StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Metrics/AbcSize:
16
+ Enabled: false
17
+
18
+ Metrics/CyclomaticComplexity:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Enabled: false
23
+
24
+ Metrics/ClassLength:
25
+ Max: 200
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.1] - 2025-03-13
4
+
5
+ - Renamed gem to Ruberto and published
6
+
7
+ ## [0.1.0] - 2025-01-30
8
+
9
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Bruno Costanzo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # Ruberto
2
+
3
+ This gem helps you seamlessly connect your Ruby app with Uber’s services. Hop in, let’s ride!
4
+
5
+ ### Why Ruberto?
6
+
7
+ It was originally named `Ruber`, because, well... it’s built in Ruby and integrates with Uber. See what we did there? 😏
8
+
9
+ Then we sadly realized that the name was already taken, so we renamed it to `Ruberto`. Hope you like it!
10
+
11
+ > The current version includes the integration with the Uber Direct API.
12
+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```
19
+ gem 'ruberto', github: "unagisoftware/ruberto"
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```
25
+ $ bundle
26
+ ```
27
+ ## Configuration
28
+ Ruberto can be customized using various configuration options. To see the full list, run the `init` generator to create an initializer with all the options. Then, uncomment the variables you want to customize.
29
+
30
+ ```bash
31
+ rails generate ruberto:init
32
+ # This will create a file ruberto.rb under config/initializers
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ To access the API, you'll need to create an account on Uber (see the [Uber developers website](https://developer.uber.com) for more information). Once you have your account, go to the developer options to find your `customer_id`, `client_id`, and `client_secret`.
38
+
39
+ You need to pass those values to the gem. You can do this from anywhere, but we recommend using an initializer like this:
40
+
41
+ ```ruby
42
+ Ruberto.configure do |config|
43
+ config.customer_id = 'uber-customer-id'
44
+ config.client_id = 'uber-client-id'
45
+ config.client_secret = 'uber-client-secret'
46
+ end
47
+ ```
48
+
49
+ _ℹ️ If you run the `init` generator you should set the attributes in the generated initializer (`config/initializers/ruberto`)_
50
+
51
+ ## Cache
52
+ Ruberto uses a caching solution to improve efficiency (e.g., for caching tokens). By default, it uses a simple memory cache,
53
+ but you can change the cache method by setting the `Ruberto.cache` attribute.
54
+
55
+ ```ruby
56
+ Ruberto.cache = Redis.new
57
+ # or
58
+ Ruberto.cache = Rails.cache
59
+ # or any object that responds to read/write/delete/clear
60
+ Ruberto.cache = YourCustomCache.new
61
+ ```
62
+
63
+ > Try not to use the memory cache in production, as it will be cleared on every request.
64
+
65
+
66
+ ### File cache
67
+
68
+ Ruberto comes with a simple File cache option. It uses a yaml file to store the cached data.
69
+
70
+ ```yml
71
+ ---
72
+ # Example of file automatically generated
73
+ :access_token:
74
+ :token: IA.VUNmGAAAAAAAEgASAAAABwAIAAwAAAAAAAAAEgAAAAAAAAGwAAAAFAAAAAAADgAQAAQAAAAIAAwAAAAOAAAAhAAAABwAAAAEAAAAEAAAAKbivxMQNu9xZfQn_LJeh75fAAAAcqjQlrRGJjknFRPDLARG0Uj0kIvmkIh7cy_HI8cPjKMP4ja0xAvKLSJ1H9eU1ALQJkExzcMwvMkPyVjpSm-c4Wk1S__oSOK_pkAX1kywZr8sBpP_gtPwBhrz3SF8L6YADAAAALkCO6lUHox2Dp907iQAAABiMGQ4NTgwMy0zOGEwLTQyYjMtODA2ZS03YTRjZjhlMTk2ZWU
75
+ :expires_at: 2025-03-27 16:46:12.256308000 -03:00
76
+ ```
77
+
78
+ In case you want to go for this option, you'll need to set the `file_cache_path` attribute to determine where to save the file.
79
+
80
+ ‼️ **Make sure that this path is in your `.gitignore` to avoid pushing your token to the repo.**
81
+
82
+ ## Resources
83
+
84
+ Ruberto maps resources from the Uber API to internal resources. For example, `Ruberto::DeliveryResource` lets you create, find, list, cancel, and manage deliveries in Uber. When you call these methods on a resource, it returns objects created using OpenStruct, allowing you to access data in a Ruby-like way.
85
+
86
+ ```ruby
87
+ delivery = Ruberto::DeliveryResource.find("del_id1231asdfas")
88
+ #=> Ruberto::Delivery
89
+ delivery.id
90
+ #=> del_id1231asdfas
91
+ ```
92
+
93
+ ### DeliveryResource
94
+
95
+ ```ruby
96
+ Ruberto::DeliveryResource.all
97
+ #=> Ruberto::Collection of Ruberto::Delivery
98
+
99
+ Ruberto::DeliveryResource.find("del_id")
100
+ #=> Ruberto::Delivery
101
+
102
+ Ruberto::DeliveryResource.create({...}}
103
+ #=> Ruberto::Delivery
104
+
105
+ Ruberto::DeliveryResource.cancel("del_id")
106
+ #=> Ruberto::Delivery
107
+
108
+ Ruberto::DeliveryResource.update("del_id", {...})
109
+ #=> Ruberto::Delivery
110
+
111
+ Ruberto::DeliveryResource.proof_of_delivery("del_id", {...})
112
+ #=> Ruberto::Delivery::ProofOfDelivery
113
+ ```
114
+
115
+ ## Authentication
116
+ To access the Uber API, you need a valid access token from Uber's OAuth service. All requests to https://api.uber.com/ use OAuth 2.0 with the client_credentials grant type.
117
+
118
+ Authentication and caching are handled automatically by the gem. The only thing you need to do is provide the required credentials (`customer_id`, `client_id`, and `client_secret`).
119
+
120
+ ## Errors
121
+ If the Uber API returns an error, a `Ruberto::Error` exception is raised. Ruberto::Error provides the following accessors: `message`, `metadata`, `status`:
122
+
123
+ ```ruby
124
+ begin
125
+ Ruberto::DeliveryResource.create(...)
126
+ rescue Ruberto::Error => error
127
+ puts error.message # "The pickup address is invalid"
128
+ puts error.metadata # { "pickup_address": "123 Fake Street, Nowhere" }
129
+ puts error.status # 400
130
+ end
131
+ ```
132
+
133
+ ## Development
134
+
135
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
136
+
137
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
138
+
139
+ ## Contributing
140
+
141
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unagisoftware/ruberto. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/unagisoftware/ruberto/blob/master/CODE_OF_CONDUCT.md).
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
146
+
147
+ ## Code of Conduct
148
+
149
+ Everyone interacting in the Ruberto project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unagisoftware/ruberto/blob/master/CODE_OF_CONDUCT.md).
150
+
151
+ ## About Unagi
152
+
153
+ <img width="208" alt="isologotipo naranja cuadrado" style="margin:auto" src="https://github.com/user-attachments/assets/05750673-b2ba-473a-b8c6-c400a4403a4a" />
154
+
155
+ This repo is maintained and funded by [Unagi](https://unagisoftware.com).
156
+
157
+ Do you want to hire us? [Let's get in touch!](https://unagisoftware.com/#contact)
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Ruberto
6
+ module Generators
7
+ class InitGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ def add_initializer
11
+ say "Copying Ruberto initializer"
12
+ template "initializers/ruberto.tt", "config/initializers/ruberto.rb"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ Ruberto.configure do |config|
2
+ # Required attributes
3
+ config.customer_id = 'uber-customer-id'
4
+ config.client_id = 'uber-client-id'
5
+ config.client_secret = 'uber-client-secret'
6
+
7
+ # --------------------------------------------------------------------------
8
+ # Cache
9
+ # --------------------------------------------------------------------------
10
+ # Ruberto comes with a File cache option. It uses a yaml file to store the cached data.
11
+ # Uncomment the following line to use the file cache. Make sure the path is in your
12
+ # .gitignore to avoid pushing your token to the repo.
13
+ # config.cache = Ruberto::FileCache.new('tmp/ruberto_cache.yaml')
14
+
15
+ # If you want to use a different cache option (like redis, memcache, etc).
16
+ # It might be any object that responds to read/write/delete/clear
17
+ # config.cache = Rails.cache unless Rails.env.test?
18
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Ruberto
6
+ class Authenticator
7
+ OAUTH_URL = "https://auth.uber.com/oauth/v2/token"
8
+ GRANT_TYPE = "client_credentials"
9
+ SCOPE = "eats.deliveries"
10
+
11
+ class << self
12
+ def access_token
13
+ @access_token = cached_token&.fetch(:token) || fetch_new_token
14
+
15
+ @access_token = refresh_access_token if token_expired?
16
+
17
+ @access_token
18
+ end
19
+
20
+ def refresh_access_token
21
+ Ruberto.cache.delete(cache_key)
22
+
23
+ fetch_new_token
24
+ end
25
+
26
+ def cache_key
27
+ @cache_key ||= "#{Ruberto.customer_id}_#{Ruberto.client_id}_access_token"
28
+ end
29
+
30
+ private
31
+
32
+ def token_expired?
33
+ cached_token[:expires_at] < Time.now
34
+ end
35
+
36
+ def cached_token
37
+ Ruberto.cache.read(cache_key)
38
+ end
39
+
40
+ def fetch_new_token
41
+ response = Faraday.post(
42
+ OAUTH_URL,
43
+ {
44
+ client_id: Ruberto.client_id,
45
+ client_secret: Ruberto.client_secret,
46
+ grant_type: GRANT_TYPE,
47
+ scope: SCOPE
48
+ }
49
+ )
50
+
51
+ data = JSON.parse(response.body.to_s)
52
+
53
+ expires_at = Time.now + data["expires_in"].to_i
54
+ Ruberto.cache.write(cache_key, { token: data["access_token"], expires_at: expires_at })
55
+
56
+ data["access_token"]
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ class Collection
5
+ attr_reader :data, :next_href
6
+
7
+ def self.from_response(response_body, type:)
8
+ new(
9
+ data: response_body[:data]&.map { |attrs| type.new(attrs) },
10
+ next_href: response_body[:next_href]
11
+ )
12
+ end
13
+
14
+ def initialize(data:, next_href:)
15
+ @data = data
16
+ @next_href = next_href
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml/store"
4
+
5
+ module Ruberto
6
+ class FileCache
7
+ def initialize(file_cache_path)
8
+ @file_cache_path = file_cache_path
9
+ @store = YAML::Store.new(file_cache_path)
10
+ end
11
+
12
+ def read(key) = @store.transaction { @store[key] }
13
+ def write(key, value) = @store.transaction { @store[key] = value }
14
+
15
+ def clear
16
+ File.delete(@file_cache_path) if File.exist?(@file_cache_path)
17
+ end
18
+
19
+ def delete(key) = @store.transaction { @store.delete(key) }
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ class Configuration
5
+ class MemoryCache
6
+ def read(key) = memory_store[key]
7
+ def write(key, value, _options = {}) = memory_store[key] = value
8
+ def clear = memory_store.clear
9
+ def delete(key) = memory_store.delete(key)
10
+ def memory_store = @memory_store ||= {}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "configuration/memory_cache"
4
+ require_relative "configuration/file_cache"
5
+
6
+ module Ruberto
7
+ class Configuration
8
+ attr_accessor :customer_id, :client_id, :client_secret
9
+
10
+ def cache
11
+ @cache ||= MemoryCache.new
12
+ end
13
+
14
+ def cache=(store)
15
+ unless %i[read write clear delete].all? { |method| store.respond_to?(method) }
16
+ raise ArgumentError, "cache_store must respond to read, write, clear, and delete"
17
+ end
18
+
19
+ @cache = store
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def configuration=(config)
29
+ if config.is_a?(Hash)
30
+ config.each do |key, value|
31
+ configuration.send "#{key}=", value
32
+ end
33
+ else
34
+ @configuration = config
35
+ end
36
+
37
+ configuration
38
+ end
39
+
40
+ def configure
41
+ yield configuration
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ class Error < StandardError
5
+ attr_reader :status, :message, :metadata
6
+
7
+ def initialize(msg, body, status)
8
+ @message = body[:message]
9
+ @metadata = body[:metadata]
10
+ @status = status
11
+
12
+ super(msg)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module Ruberto
6
+ class Object < OpenStruct
7
+ def initialize(attributes)
8
+ super(to_ostruct(attributes))
9
+ end
10
+
11
+ def to_ostruct(obj)
12
+ if obj.is_a?(Hash)
13
+ OpenStruct.new(obj.transform_values { |val| to_ostruct(val) })
14
+ elsif obj.is_a?(Array)
15
+ obj.map { |o| to_ostruct(o) }
16
+ else
17
+ obj
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ class Delivery < Object
5
+ class ProofOfDelivery < Object; end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ class ProofOfDelivery < Object
5
+ end
6
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/net_http_persistent"
5
+
6
+ module Ruberto
7
+ class Request
8
+ BASE_URL = "https://api.uber.com/v1"
9
+
10
+ def initialize(url)
11
+ @url = url
12
+ end
13
+
14
+ def get(params: {})
15
+ handle_response connection.get(@url, params)
16
+ end
17
+
18
+ def post(body: {}, headers: {})
19
+ handle_response connection.post(@url, body, headers)
20
+ end
21
+
22
+ def patch(body:, headers: {})
23
+ handle_response connection.patch(@url, body, headers)
24
+ end
25
+
26
+ def put(body:, headers: {})
27
+ handle_response connection.put(@url, body, headers)
28
+ end
29
+
30
+ def delete(params: {}, headers: {})
31
+ handle_response connection.delete(@url, params, headers)
32
+ end
33
+
34
+ private
35
+
36
+ def connection
37
+ @connection ||= Faraday.new do |conn|
38
+ conn.url_prefix = BASE_URL
39
+ conn.request :authorization, :Bearer, Ruberto::Authenticator.access_token
40
+ conn.request :json
41
+ conn.response :json, content_type: "application/json", parser_options: { symbolize_names: true }
42
+ end
43
+ end
44
+
45
+ def handle_response(response)
46
+ return response if response.status == 200
47
+
48
+ raise Ruberto::Error.new(response.body[:message], response.body, response.status)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ class DeliveryResource
5
+ class << self
6
+ def all(**params)
7
+ response = Request.new("customers/#{Ruberto.customer_id}/deliveries").get(params: params)
8
+
9
+ Collection.from_response(response.body, type: Delivery)
10
+ end
11
+
12
+ def find(id)
13
+ response = Request.new("customers/#{Ruberto.customer_id}/deliveries/#{id}").get
14
+
15
+ Delivery.new response.body
16
+ end
17
+
18
+ def create(params)
19
+ response = Request.new("customers/#{Ruberto.customer_id}/deliveries").post(body: params)
20
+
21
+ Delivery.new response.body
22
+ end
23
+
24
+ def cancel(id)
25
+ response = Request.new("customers/#{Ruberto.customer_id}/deliveries/#{id}/cancel").post
26
+
27
+ Delivery.new response.body
28
+ end
29
+
30
+ def update(id, params)
31
+ response = Request.new("customers/#{Ruberto.customer_id}/deliveries/#{id}").post(body: params)
32
+
33
+ Delivery.new response.body
34
+ end
35
+
36
+ def proof_of_delivery(id, params)
37
+ response = Request.new("customers/#{Ruberto.customer_id}/deliveries/#{id}/proof_of_delivery").post(body: params)
38
+
39
+ Delivery::ProofOfDelivery.new response.body
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruberto
4
+ VERSION = "0.1.1"
5
+ end
data/lib/ruberto.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruberto/version"
4
+ require "forwardable"
5
+ require "ruberto/configuration"
6
+ require "ruberto/authenticator"
7
+ require "ruberto/request"
8
+ require "ruberto/resources/delivery_resource"
9
+ require "ruberto/error"
10
+
11
+ # a Ruby wrapper for Uber API
12
+ module Ruberto
13
+ autoload :Client, "ruberto/client"
14
+ autoload :Error, "ruberto/error"
15
+ autoload :Authenticator, "ruberto/authenticator"
16
+ autoload :Object, "ruberto/object"
17
+
18
+ autoload :DeliveryResource, "ruberto/resources/delivery_resource"
19
+
20
+ autoload :Collection, "ruberto/collection"
21
+ autoload :Delivery, "ruberto/objects/delivery"
22
+
23
+ DEFAULT_API_BASE = "https://api.uber.com/v1"
24
+
25
+ Faraday.default_adapter = :net_http_persistent
26
+
27
+ class << self
28
+ extend Forwardable
29
+
30
+ def_delegators(
31
+ :configuration, :customer_id, :client_id, :client_secret,
32
+ :customer_id=, :client_id=, :client_secret=, :cache, :cache=
33
+ )
34
+ end
35
+ end
data/sig/ruber.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Ruberto
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruberto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Costanzo
8
+ - Nicolás Galdámez
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2025-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday-net_http_persistent
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Ruby bindings for Uber's API
43
+ email:
44
+ - bruno.costanzo@unagisoftware.com
45
+ - nicolas.galdamez@unagisoftware.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".env"
51
+ - ".rubocop.yml"
52
+ - CHANGELOG.md
53
+ - CODE_OF_CONDUCT.md
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - lib/generators/ruberto/init_generator.rb
58
+ - lib/generators/ruberto/templates/initializers/ruberto.tt
59
+ - lib/ruberto.rb
60
+ - lib/ruberto/authenticator.rb
61
+ - lib/ruberto/collection.rb
62
+ - lib/ruberto/configuration.rb
63
+ - lib/ruberto/configuration/file_cache.rb
64
+ - lib/ruberto/configuration/memory_cache.rb
65
+ - lib/ruberto/error.rb
66
+ - lib/ruberto/object.rb
67
+ - lib/ruberto/objects/delivery.rb
68
+ - lib/ruberto/objects/proof_of_delivery.rb
69
+ - lib/ruberto/request.rb
70
+ - lib/ruberto/resources/delivery_resource.rb
71
+ - lib/ruberto/version.rb
72
+ - sig/ruber.rbs
73
+ homepage: https://github.com/unagisoftware/ruberto
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/unagisoftware/ruberto
78
+ source_code_uri: https://github.com/unagisoftware/ruberto
79
+ changelog_uri: https://github.com/unagisoftware/ruberto/blob/main/CHANGELOG.md
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.4.10
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby bindings for Uber's API
99
+ test_files: []