monzo 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d7a10b8bf9ee4689cb437e878d0746ffef7cb2f
4
+ data.tar.gz: d07b17c677bda9e8a3256b2be84956593e2513bb
5
+ SHA512:
6
+ metadata.gz: 8be1dd299af506ab18024f295cc850a2cc025eb1a99baa69e0ae911a4b03c468cfa639a90f81cd954273fcd76232d386effa9bae7212fe99132c926d132a2cd7
7
+ data.tar.gz: b9eb8212fb0a695091712b73d2b3758e8b41e848b6da453113e13e1ffb4002528eae17695ac91517f9109cf74ca51ababf0e09918b2dae6f6c64c3fc46788501
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at murray.sum@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monzo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Murray Summers
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,129 @@
1
+ # Monzo
2
+
3
+ A simple interface to make requests to the Monzo API. Full API documentation can be found at [https://monzo.com/docs/](https://monzo.com/docs/).
4
+
5
+ Before using this gem please ensure you read [Monzo's update on their API](https://monzo.com/blog/2017/05/11/api-update/) ensuring you understand Monzo's development plans and are happy that they are likely to introduce backwards-incompatible changes to the API when developing the new Current Account functionality.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "monzo"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install monzo
22
+
23
+ ## Usage
24
+
25
+ ### Introduction
26
+
27
+ The Monzo API implements OAuth 2.0 to allow users to log in to applications without exposing their credentials. The process involves several steps:
28
+
29
+ 1. Acquire an access token, and optionally a refresh token
30
+ 2. Use the access token to make authenticated requests
31
+ 3. If you were issued a refresh token: refresh the access token when it expires
32
+
33
+ Before you begin, you will need to create a client in the developer tools. To understand how to acquire an access token see the [Monzo API documentation](https://monzo.com/docs/#authentication)
34
+
35
+ Once you have acquired an access token you can configure the gem to use it. Firstly require the gem:
36
+
37
+ ```ruby
38
+ require "monzo"
39
+ ```
40
+
41
+ Then configure your access token:
42
+
43
+ ```ruby
44
+ Monzo.configure("access_token")
45
+ ```
46
+
47
+ After you have set your access token you can now make requests.
48
+
49
+ ### Accounts
50
+
51
+ Accounts represent a store of funds, and have a list of transactions. [Docs](https://monzo.com/docs/#accounts)
52
+
53
+ ```ruby
54
+ # Find all Monzo Accounts
55
+ Monzo::Account.all
56
+ ```
57
+
58
+ ### Balance
59
+
60
+ Retrieve information about an account’s balance. [Docs](https://monzo.com/docs/#balance)
61
+
62
+ ```ruby
63
+ # Find the balance of the given account id
64
+ Monzo::Balance.find(account_id)
65
+ ```
66
+
67
+ ### Transactions
68
+
69
+ Transactions are movements of funds into or out of an account. Negative transactions represent debits (ie. spending money) and positive transactions represent credits (ie. receiving money). [Docs](https://monzo.com/docs/#transactions)
70
+
71
+ ```ruby
72
+ # Find a transaction with the given transaction id.
73
+ Monzo::Transaction.find(transaction_id)
74
+
75
+ # Find all the transactions for a given account id.
76
+ Monzo::Transaction.all(account_id)
77
+
78
+ # Create an annotation for a given transaction id.
79
+ metadata = { :foo => "bar" }
80
+ Monzo::Transaction.create_annotation(transaction_id, metadata)
81
+ ```
82
+
83
+ ### Feed Items
84
+
85
+ The Monzo app is organised around the feed – a reverse-chronological stream of events. Transactions are one such feed item, and your application can create its own feed items to surface relevant information to the user. [Docs](https://monzo.com/docs/#feed-items)
86
+
87
+ ```ruby
88
+ # Create a feed item on a user's feed.
89
+ feed_item_type = "basic"
90
+ feed_item_params = {
91
+ :title => "Hello World",
92
+ :image_url => "https://www.example.com/image.png"
93
+ }
94
+ url = "https://www.example.com"
95
+ Monzo::FeedItem.create(account_id, feed_item_type, feed_item_params, url)
96
+ ```
97
+
98
+ ### Webhooks
99
+
100
+ Webhooks allow your application to receive real-time, push notification of events in an account. [Docs](https://monzo.com/docs/#webhooks)
101
+
102
+ ```ruby
103
+ # Create a webhook for the given account id.
104
+ Monzo::Webhook.create(account_id, "https://example.com")
105
+
106
+ # Find all webhooks for a given account id.
107
+ Monzo::Webhook.all(account_id)
108
+
109
+ # Delete a webhook.
110
+ Monzo::Webhook.delete(webhook_id)
111
+ ```
112
+
113
+ ## Development
114
+
115
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
116
+
117
+ ## Contributing
118
+
119
+ Bug reports and pull requests are welcome on GitHub at https://github.com/murraysum/monzo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
120
+
121
+ 1. Fork it
122
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
123
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
124
+ 4. Push to the branch (`git push origin my-new-feature`)
125
+ 5. Create new Pull Request
126
+
127
+ ## License
128
+
129
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "monzo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/monzo.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "json"
2
+
3
+ require "monzo/version"
4
+ require "monzo/account"
5
+ require "monzo/balance"
6
+ require "monzo/transaction"
7
+ require "monzo/feed_item"
8
+ require "monzo/webhook"
9
+ require "monzo/client"
10
+ require "monzo/configuration"
11
+
12
+ module Monzo
13
+
14
+ # Public: Set the configuration options such as the accces token.
15
+ #
16
+ # access_token - The access_token to authenticate with.
17
+ #
18
+ # Returns: an instance of Monzo::Configuration.
19
+ def self.configure(access_token)
20
+ @configuration = Monzo::Configuration.new(access_token)
21
+ end
22
+
23
+ # Internal: The http client to perform requests.
24
+ def self.client
25
+ Monzo::Client.new(@configuration.access_token)
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ module Monzo
2
+
3
+ # Public: Accounts represent a store of funds, and have a list of transactions.
4
+ class Account
5
+
6
+ attr_reader :id, :description, :created
7
+
8
+ # Public: Initialize an Account.
9
+ #
10
+ # params - A Hash of account parameters.
11
+ def initialize(params)
12
+ @id = params[:id]
13
+ @description = params[:description]
14
+ @created = params[:created]
15
+ end
16
+
17
+ # Public: Find all Monzo Accounts
18
+ #
19
+ # Returns An Array of Monzo::Account
20
+ def self.all
21
+ client = Monzo.client
22
+ response = client.get("/accounts")
23
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
24
+
25
+ parsed_response[:accounts].map do |item|
26
+ Monzo::Account.new(item)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ module Monzo
2
+
3
+ # Public: Retrieve information about an account’s balance.
4
+ class Balance
5
+
6
+ attr_reader :balance, :currency, :spend_today, :local_currency,
7
+ :local_exchange_rate, :local_spend
8
+
9
+ # Public: Initialize a Balance.
10
+ #
11
+ # params - A Hash of balance parameters.
12
+ def initialize(params)
13
+ @balance = params[:balance]
14
+ @currency = params[:currency]
15
+ @spend_today = params[:spend_today]
16
+ @local_currency = params[:local_currency]
17
+ @local_exchange_rate = params[:local_exchange_rate]
18
+ @local_spend = params[:local_spend]
19
+ end
20
+
21
+ # Public: Find the balance of the given account id.
22
+ #
23
+ # account_id - The Monzo account id to find the balance for.
24
+ #
25
+ # Returns an instance of Monzo::Balance
26
+ def self.find(account_id)
27
+ client = Monzo.client
28
+ response = client.get("/balance", {:account_id => account_id})
29
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
30
+
31
+ Monzo::Balance.new(parsed_response)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,123 @@
1
+ require "net/https"
2
+ require "uri"
3
+
4
+ module Monzo
5
+
6
+ # Internal: A client to perform HTTPS requests to the Monzo API.
7
+ class Client
8
+
9
+ # Public: Returns the access token used to authenticate with.
10
+ attr_reader :access_token
11
+
12
+ # Public: Initialize a Monzo::Client to make HTTP requests
13
+ #
14
+ # access_token - The access_token to authenticate with.
15
+ def initialize(access_token)
16
+ @access_token = access_token
17
+ end
18
+
19
+ # Internal: Perform a GET request to the Monzo API.
20
+ #
21
+ # path - The URI path to request.
22
+ # options - A Hash of query options to include in the URI.
23
+ #
24
+ # Returns a HTTP response.
25
+ def get(path, options = {})
26
+ uri = build_uri(path, options)
27
+
28
+ request = Net::HTTP::Get.new(uri.request_uri)
29
+ set_authorisation_header(request)
30
+
31
+ response = https_client(uri).request(request)
32
+ end
33
+
34
+ # Internal: Perform a POST request to the Monzo API.
35
+ #
36
+ # path - The URI path to request.
37
+ # data - The form data to send with the request.
38
+ # options - A Hash of query options to include in the URI.
39
+ #
40
+ # Returns a HTTP response.
41
+ def post(path, data, options = {})
42
+ uri = build_uri(path, options)
43
+
44
+ request = Net::HTTP::Post.new(uri.request_uri)
45
+ set_authorisation_header(request)
46
+ request.set_form_data(data)
47
+
48
+ response = https_client(uri).request(request)
49
+ end
50
+
51
+ # Internal: Perform a PATCH request to the Monzo API.
52
+ #
53
+ # path - The URI path to request.
54
+ # data - The form data to send with the request.
55
+ # options - A Hash of query options to include in the URI.
56
+ #
57
+ # Returns a HTTP response.
58
+ def patch(path, data, options = {})
59
+ uri = build_uri(path, options)
60
+
61
+ request = Net::HTTP::Patch.new(uri.request_uri)
62
+ set_authorisation_header(request)
63
+ request.set_form_data(data)
64
+
65
+ response = https_client(uri).request(request)
66
+ end
67
+
68
+ # Internal: Perform a DELETE request to the Monzo API.
69
+ #
70
+ # path - The URI path to request.
71
+ #
72
+ # Returns a HTTP response.
73
+ def delete(path)
74
+ uri = build_uri(path)
75
+
76
+ request = Net::HTTP::Delete.new(uri.request_uri)
77
+ set_authorisation_header(request)
78
+
79
+ response = https_client(uri).request(request)
80
+ end
81
+
82
+ private
83
+
84
+ # Internal: Build a URI for the given path and query options
85
+ #
86
+ # path - The URI path for the URI.
87
+ # options - The query options for the URI.
88
+ #
89
+ # Returns an instance of URI for the Monzo API.
90
+ def build_uri(path, options = {})
91
+ uri = URI.join(host, path)
92
+ uri.query = URI.encode_www_form(options)
93
+ uri
94
+ end
95
+
96
+ # Internal: Build a HTTPS client for the given URI for requests to be issued.
97
+ #
98
+ # uri - The URI for the client to request.
99
+ #
100
+ # Returns an instance of Net::HTTP.
101
+ def https_client(uri)
102
+ http = Net::HTTP.new(uri.host, uri.port)
103
+ http.use_ssl = true
104
+ http
105
+ end
106
+
107
+ # Internal: Set an authorisation header with the access token for the request
108
+ #
109
+ # request - The HTTP request to add the request header
110
+ #
111
+ # Returns nothing.
112
+ def set_authorisation_header(request)
113
+ request["Authorization"] = "Bearer #{access_token}"
114
+ end
115
+
116
+ # Internal: The host name for the Monzo API
117
+ #
118
+ # Returns a host name as a String.
119
+ def host
120
+ "https://api.monzo.com/"
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,15 @@
1
+ module Monzo
2
+
3
+ # Internal: Store configuration options for the gem.
4
+ class Configuration
5
+
6
+ attr_accessor :access_token
7
+
8
+ # Internal: Initialize a Configuration.
9
+ #
10
+ # access_token - The access_token to authenticate with.
11
+ def initialize(access_token)
12
+ @access_token = access_token
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ module Monzo
2
+
3
+ # Public: The Monzo app is organised around the feed – a
4
+ # reverse-chronological stream of events. Transactions
5
+ # are one such feed item, and your application can
6
+ # create its own feed items to surface relevant information
7
+ # to the user.
8
+ class FeedItem
9
+
10
+ attr_reader :account_id, :type, :params, :url
11
+
12
+ # Public: Initialize a FeedItem.
13
+ #
14
+ # params - A Hash of feed item parameters.
15
+ def initialize(params)
16
+ @account_id = params[:account_id]
17
+ @type = params[:type]
18
+ @params = params[:params]
19
+ @url = params[:url]
20
+ end
21
+
22
+ # Public: Create a feed item on a user's feed.
23
+ #
24
+ # account_id - The account id to create a feed item for.
25
+ # type - Type of feed item. Currently only basic is supported.
26
+ # params - A Hash of parameters which vary based on type.
27
+ # url - A URL to open when the feed item is tapped.
28
+ # If no URL is provided, the app will display a fallback
29
+ # view based on the title & body. (optional)
30
+ #
31
+ # Returns: An empty Hash.
32
+ def self.create(account_id, type, params, url = nil)
33
+ client = Monzo.client
34
+
35
+ data = {
36
+ "account_id" => account_id,
37
+ "type" => type,
38
+ "params[title]" => params[:title],
39
+ "params[image_url]" => params[:image_url],
40
+ "params[background_color]" => params[:background_color],
41
+ "params[body_color]" => params[:body_color],
42
+ "params[title_color]" => params[:title_color],
43
+ "params[body]" => params[:body],
44
+ "url" => url
45
+ }
46
+ response = client.post("/feed", data, {})
47
+ JSON.parse(response.body, :symbolize_names => true)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,89 @@
1
+ module Monzo
2
+
3
+ # Public: Transactions are movements of funds into or out of an account.
4
+ # Negative transactions represent debits (ie. spending money) and
5
+ # positive transactions represent credits (ie. receiving money).
6
+ class Transaction
7
+
8
+ attr_reader :id, :created, :description, :amount, :currency,
9
+ :merchant, :notes, :metadata, :account_balance, :attachments,
10
+ :category, :is_load, :settled, :local_amount, :local_currency,
11
+ :updated, :account_id, :counterparty, :scheme, :dedupe_id,
12
+ :originator, :include_in_spending
13
+
14
+ # Public: Initialize a Transaction.
15
+ #
16
+ # params - A Hash of transaction parameters.
17
+ def initialize(params)
18
+ @id = params[:id]
19
+ @created = params[:created]
20
+ @description = params[:description]
21
+ @amount = params[:amount]
22
+ @currency = params[:currency]
23
+ @merchant = params[:merchant]
24
+ @notes = params[:notes]
25
+ @metadata = params[:metadata]
26
+ @account_balance = params[:account_balance]
27
+ @attachments = params[:attachments]
28
+ @category = params[:category]
29
+ @is_load = params[:is_load]
30
+ @settled = params[:settled]
31
+ @local_amount = params[:local_amount]
32
+ @local_currency = params[:local_currency]
33
+ @updated = params[:updated]
34
+ @account_id = params[:account_id]
35
+ @counterparty = params[:counterparty]
36
+ @scheme = params[:scheme]
37
+ @dedupe_id = params[:dedupe_id]
38
+ @originator = params[:originator]
39
+ @include_in_spending = params[:include_in_spending]
40
+ end
41
+
42
+ # Public: Find a transaction with the given transaction id.
43
+ #
44
+ # transaction_id - The id to find.
45
+ # options - a Hash of options to request further information such as the
46
+ # merchant information (optional)
47
+ #
48
+ # Returns an instance of Monzo::Transaction.
49
+ def self.find(transaction_id, options = {})
50
+ response = Monzo.client.get("/transactions/#{transaction_id}", options)
51
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
52
+
53
+ Monzo::Transaction.new(parsed_response[:transaction])
54
+ end
55
+
56
+ # Public: Find all the transactions for a given account id.
57
+ #
58
+ # account_id - The account id to retrieve transactions from.
59
+ #
60
+ # Returns an Array of Monzo::Transaction.
61
+ def self.all(account_id)
62
+ response = Monzo.client.get("/transactions", :account_id => account_id)
63
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
64
+
65
+ parsed_response[:transactions].map do |item|
66
+ Monzo::Transaction.new(item)
67
+ end
68
+ end
69
+
70
+ # Public: Create an annotation for a given transaction id. You may store
71
+ # your own key-value annotations against a transaction in its metadata.
72
+ #
73
+ # transaction_id - The transaction id to annotate.
74
+ # metadata - a hash of annotations to add.
75
+ #
76
+ # Returns an instance of Monzo::Transaction with the annotations.
77
+ def self.create_annotation(transaction_id, metadata)
78
+ data = {}
79
+ metadata.each do |k, v|
80
+ data["metadata[#{k.to_s}]"] = v
81
+ end
82
+ response = Monzo.client.patch("/transactions/#{transaction_id}", data, {})
83
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
84
+
85
+ Monzo::Transaction.new(parsed_response[:transaction])
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,4 @@
1
+ module Monzo
2
+ # Public: The version number of the gem.
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,66 @@
1
+ module Monzo
2
+
3
+ # Public: Webhooks allow your application to receive real-time,
4
+ # push notification of events in an account.
5
+ class Webhook
6
+
7
+ attr_reader :id, :account_id, :url
8
+
9
+ # Public: Initialize a Webhook.
10
+ #
11
+ # params - A Hash of webhook parameters.
12
+ def initialize(params)
13
+ @id = params[:id]
14
+ @account_id = params[:account_id]
15
+ @url = params[:url]
16
+ end
17
+
18
+ # Public: Create a webhook for the given account id.
19
+ #
20
+ # account_id - The account to receive event notifications for.
21
+ # url - The URL Monzo will send notifications to.
22
+ #
23
+ # Returns an instance of Monzo::Webhook.
24
+ def self.create(account_id, url)
25
+ client = Monzo.client
26
+
27
+ data = {
28
+ "account_id" => account_id,
29
+ "url" => url
30
+ }
31
+ response = client.post("/webhooks", data, {})
32
+
33
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
34
+ Monzo::Webhook.new(parsed_response[:webhook])
35
+ end
36
+
37
+ # Public: Find all webhooks for a given account id.
38
+ #
39
+ # account_id - The account id to list registered webhooks for.
40
+ #
41
+ # Returns an Array of Monzo::Webhook instances.
42
+ def self.all(account_id)
43
+ client = Monzo.client
44
+
45
+ response = client.get("/webhooks", :account_id => account_id)
46
+
47
+ parsed_response = JSON.parse(response.body, :symbolize_names => true)
48
+
49
+ parsed_response[:webhooks].map do |item|
50
+ Monzo::Webhook.new(item)
51
+ end
52
+ end
53
+
54
+ # Public: Delete a webhook.
55
+ #
56
+ # webhook_id - The webhook id to be deleted.
57
+ #
58
+ # Returns an empty Hash.
59
+ def self.delete(webhook_id)
60
+ client = Monzo.client
61
+
62
+ response = client.delete("/webhooks/#{webhook_id}")
63
+ JSON.parse(response.body, :symbolize_names => true)
64
+ end
65
+ end
66
+ end
data/monzo.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "monzo/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "monzo"
8
+ spec.version = Monzo::VERSION
9
+ spec.authors = ["Murray Summers"]
10
+ spec.email = ["murray.sum@gmail.com"]
11
+
12
+ spec.summary = "A simple interface to make requests to the Monzo API"
13
+ spec.homepage = "https://github.com/murraysum/monzo"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "webmock", "~> 3.0"
27
+ spec.add_development_dependency "factory_girl", "4.7.0"
28
+ spec.add_development_dependency "byebug", "~> 9.0"
29
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monzo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Murray Summers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 4.7.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 4.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '9.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '9.0'
97
+ description:
98
+ email:
99
+ - murray.sum@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/monzo.rb
116
+ - lib/monzo/account.rb
117
+ - lib/monzo/balance.rb
118
+ - lib/monzo/client.rb
119
+ - lib/monzo/configuration.rb
120
+ - lib/monzo/feed_item.rb
121
+ - lib/monzo/transaction.rb
122
+ - lib/monzo/version.rb
123
+ - lib/monzo/webhook.rb
124
+ - monzo.gemspec
125
+ homepage: https://github.com/murraysum/monzo
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: A simple interface to make requests to the Monzo API
149
+ test_files: []