instamojo-ruby 1.1.2
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 +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +83 -0
- data/LICENSE.txt +20 -0
- data/README.md +287 -0
- data/README.rdoc +89 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/instamojo-ruby.gemspec +79 -0
- data/lib/API/api.rb +47 -0
- data/lib/Instamojo-rb.rb +15 -0
- data/lib/base.rb +8 -0
- data/lib/client/client.rb +227 -0
- data/lib/client/link.rb +60 -0
- data/lib/client/payment.rb +60 -0
- data/lib/client/payment_request.rb +44 -0
- data/lib/client/refund.rb +35 -0
- data/lib/common_object.rb +54 -0
- data/lib/response.rb +26 -0
- data/lib/utility.rb +15 -0
- data/spec/Instamojo-rb_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c22eccfe2814ce57f124728f71fce854c27760ee83584420a2989e859e976df
|
4
|
+
data.tar.gz: 889f92aee37dd3305ba01be179f0c7189248f9e9c96e3cb9b639d9c21290c86f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 945216e78b02a84146f03a40224627c45d7af8563a44687512f0747f7311cb60d54b612fe97c98da2dfa04d3d486be8fa68ce09eb7b4e2437943a63354a993b7
|
7
|
+
data.tar.gz: e9df688d4cc84207fd549c276bd693ce3d41137262290fadc01e21edf82b486193b578543dccdc475566daf1227611d9ebb505a200008a76fced302a9d3f4652
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "faraday", "0.8.8"
|
6
|
+
gem 'rest-client', '~> 1.8'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.8"
|
12
|
+
gem "bundler", "~> 1.0"
|
13
|
+
gem "jeweler", "~> 1.8"
|
14
|
+
gem "debugger", "~> 1.6"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
columnize (0.3.6)
|
7
|
+
debugger (1.6.5)
|
8
|
+
columnize (>= 0.3.1)
|
9
|
+
debugger-linecache (~> 1.2.0)
|
10
|
+
debugger-ruby_core_source (~> 1.3.1)
|
11
|
+
debugger-linecache (1.2.0)
|
12
|
+
debugger-ruby_core_source (1.3.1)
|
13
|
+
diff-lcs (1.1.3)
|
14
|
+
domain_name (0.5.25)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
faraday (0.8.8)
|
17
|
+
multipart-post (~> 1.2.0)
|
18
|
+
git (1.2.6)
|
19
|
+
github_api (0.10.1)
|
20
|
+
addressable
|
21
|
+
faraday (~> 0.8.1)
|
22
|
+
hashie (>= 1.2)
|
23
|
+
multi_json (~> 1.4)
|
24
|
+
nokogiri (~> 1.5.2)
|
25
|
+
oauth2
|
26
|
+
hashie (2.0.5)
|
27
|
+
highline (1.6.20)
|
28
|
+
http-cookie (1.0.2)
|
29
|
+
domain_name (~> 0.5)
|
30
|
+
httpauth (0.2.0)
|
31
|
+
jeweler (1.8.8)
|
32
|
+
builder
|
33
|
+
bundler (~> 1.0)
|
34
|
+
git (>= 1.2.5)
|
35
|
+
github_api (= 0.10.1)
|
36
|
+
highline (>= 1.6.15)
|
37
|
+
nokogiri (= 1.5.10)
|
38
|
+
rake
|
39
|
+
rdoc
|
40
|
+
json (1.8.1)
|
41
|
+
jwt (0.1.8)
|
42
|
+
multi_json (>= 1.5)
|
43
|
+
mime-types (2.99)
|
44
|
+
multi_json (1.8.2)
|
45
|
+
multi_xml (0.5.5)
|
46
|
+
multipart-post (1.2.0)
|
47
|
+
netrc (0.11.0)
|
48
|
+
nokogiri (1.5.10)
|
49
|
+
oauth2 (0.9.2)
|
50
|
+
faraday (~> 0.8)
|
51
|
+
httpauth (~> 0.2)
|
52
|
+
jwt (~> 0.1.4)
|
53
|
+
multi_json (~> 1.0)
|
54
|
+
multi_xml (~> 0.5)
|
55
|
+
rack (~> 1.2)
|
56
|
+
rack (1.5.2)
|
57
|
+
rake (10.1.1)
|
58
|
+
rdoc (3.12.2)
|
59
|
+
json (~> 1.4)
|
60
|
+
rest-client (1.8.0)
|
61
|
+
http-cookie (>= 1.0.2, < 2.0)
|
62
|
+
mime-types (>= 1.16, < 3.0)
|
63
|
+
netrc (~> 0.7)
|
64
|
+
rspec (2.8.0)
|
65
|
+
rspec-core (~> 2.8.0)
|
66
|
+
rspec-expectations (~> 2.8.0)
|
67
|
+
rspec-mocks (~> 2.8.0)
|
68
|
+
rspec-core (2.8.0)
|
69
|
+
rspec-expectations (2.8.0)
|
70
|
+
diff-lcs (~> 1.1.2)
|
71
|
+
rspec-mocks (2.8.0)
|
72
|
+
unf (0.2.0.beta2)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
bundler (~> 1.0)
|
79
|
+
debugger (~> 1.6)
|
80
|
+
faraday (= 0.8.8)
|
81
|
+
jeweler (~> 1.8)
|
82
|
+
rest-client (~> 1.8)
|
83
|
+
rspec (~> 2.8)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Ankur Goel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,287 @@
|
|
1
|
+
# Instamojo-rb
|
2
|
+
This is the **Ruby** library of [Instamojo REST API](https://www.instamojo.com/developers/rest/).
|
3
|
+
This will assist you to programmatically create, edit and delete links on Instamojo. Also supports [RAP](https://www.instamojo.com/developers/request-a-payment-api/) api for payments request, listing and status.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
`gem install instamojo-ruby`
|
7
|
+
For your Rails/bundler projects:
|
8
|
+
`gem 'instamojo-ruby'`
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
### Set API keys
|
12
|
+
```ruby
|
13
|
+
require 'Instamojo-rb'
|
14
|
+
api = Instamojo::API.new do |app|
|
15
|
+
app.api_key = "api_key-you-received-from-api@instamojo.com"
|
16
|
+
app.auth_token = "auth_token-you-received-from-api@instamojo.com"
|
17
|
+
end
|
18
|
+
#or
|
19
|
+
api = Instamojo::API.new("api_key-you-received-from-api@instamojo.com", "auth_token-you-received-from-api@instamojo.com")
|
20
|
+
```
|
21
|
+
|
22
|
+
**Note**: If you're using this wrapper with our sandbox environment `https://test.instamojo.com/` then you should pass `'https://test.instamojo.com/api/1.1/'` as third argument to the `Instamojo` class while initializing it. API key and Auth token for the same can be obtained from https://test.instamojo.com/developers/ (Details: [Test Or Sandbox Account](https://instamojo.zendesk.com/hc/en-us/articles/208485675-Test-or-Sandbox-Account)).
|
23
|
+
|
24
|
+
api = Instamojo::API.new("api_key", "auth_token", "https://test.instamojo.com/api/1.1/")
|
25
|
+
|
26
|
+
### Generate client
|
27
|
+
`client = api.client`
|
28
|
+
|
29
|
+
---
|
30
|
+
### Products
|
31
|
+
|
32
|
+
`Link` object contains all the necessary information required to interpret, modify and archive an Instamojo product. All product operations on client returns one or collection of `products`. Original response from Instamojo API for a product is encapsulated in `link.original`, which is immutable. Call `#to_h` on `link` to get its all attributes.
|
33
|
+
_Helper methods_ for `Link`:
|
34
|
+
* `link.to_h` - Returns equivalent Ruby hash for a link.
|
35
|
+
* `link.to_json` - Returns equivalent JSON for a link
|
36
|
+
* `link.original` - Returns original link data fetched from API.
|
37
|
+
* `link.save` - Edits updates carried out on Link object at Instamojo.
|
38
|
+
* `link.archive` - Archives link at Instamojo
|
39
|
+
* `link.reload` or `link.refresh` - Looks for changes on Instamojo server for the link. Immutable
|
40
|
+
* `link.reload!` or `link.refresh!` - Same as `link.reload`, but mutable.
|
41
|
+
|
42
|
+
More about its usage is below.
|
43
|
+
|
44
|
+
|
45
|
+
#### Get Products
|
46
|
+
```ruby
|
47
|
+
client.links_list
|
48
|
+
#=> Array of Instamojo::Link objects
|
49
|
+
```
|
50
|
+
##### Supports optional pagination
|
51
|
+
```ruby
|
52
|
+
client.links_list(page:1, limit:10)
|
53
|
+
#=> Array of 10 Link objects (page 1)
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Create a new product
|
57
|
+
##### Required:
|
58
|
+
* `title` - Title of the product, be concise.
|
59
|
+
* `description` - Describe what your customers will get, you can add terms and conditions and any other relevant information here. Markdown is supported, popular media URLs like Youtube, Flickr are auto-embedded.
|
60
|
+
* `base_price` - Price of the product. This may be 0, if you want to offer it for free.
|
61
|
+
|
62
|
+
##### File and Cover image:
|
63
|
+
* `file_upload` - Full path to the file you want to sell. This file will be available only after successful payment.
|
64
|
+
* `cover_image` - Full path to the IMAGE you want to upload as a cover image.
|
65
|
+
|
66
|
+
##### Quantity:
|
67
|
+
* `quantity` - Set to 0 for unlimited sales. If you set it to say 10, a total of 10 sales will be allowed after which the product will be made unavailable.
|
68
|
+
|
69
|
+
##### Post Purchase Note
|
70
|
+
* `note` - A post-purchase note, will only displayed after successful payment. Will also be included in the ticket/ receipt that is sent as attachment to the email sent to buyer. This will not be shown if the payment fails.
|
71
|
+
|
72
|
+
##### Event
|
73
|
+
* `start_date` - Date-time when the event is beginning. Format: `YYYY-MM-DD HH:mm`
|
74
|
+
* `end_date` - Date-time when the event is ending. Format: `YYYY-MM-DD HH:mm`
|
75
|
+
* `venue` - Address of the place where the event will be held.
|
76
|
+
* `timezone` - Timezone of the venue. Example: Asia/Kolkata
|
77
|
+
|
78
|
+
##### Redirects and Webhooks
|
79
|
+
* `redirect_url` - This can be a Thank-You page on your website. Buyers will be redirected to this page after successful payment.
|
80
|
+
* `webhook_url` - Set this to a URL that can accept POST requests made by Instamojo server after successful payment.
|
81
|
+
* `enable_pwyw` - set this to True, if you want to enable Pay What You Want. Default is False.
|
82
|
+
* `enable_sign` - set this to True, if you want to enable Link Signing. Default is False. For more information regarding this, and to avail this feature write to support at instamojo.com.
|
83
|
+
|
84
|
+
##### Code:
|
85
|
+
```ruby
|
86
|
+
new_link = client.create_link do |link|
|
87
|
+
link.title = 'API product v1.1'
|
88
|
+
link.description = 'Dummy offer via API'
|
89
|
+
link.currency = 'INR'
|
90
|
+
link.base_price = 0
|
91
|
+
link.quantity = 10
|
92
|
+
link.redirect_url = 'http://ankurgoel.com'
|
93
|
+
link.file_upload = '~/Pictures/RISE.jpg'
|
94
|
+
link.cover_image = '~/Pictures/saturday.jpg'
|
95
|
+
end
|
96
|
+
#=> Instamojo Link(slug: api-product-v11, title: API product v1.1, shorturl: )
|
97
|
+
new_link.reload!
|
98
|
+
#=> Instamojo Link(slug: api-product-v11, title: API product v1.1, shorturl: http://imojo.in/1dxv1h)
|
99
|
+
```
|
100
|
+
or
|
101
|
+
```ruby
|
102
|
+
new_product_params = {base_price: 199, title: 'API product 3', description: 'My dummy offer via API', currency: 'INR', quantity: 20}
|
103
|
+
new_link = client.create_link(new_product_params)
|
104
|
+
```
|
105
|
+
|
106
|
+
#### Details of a product
|
107
|
+
```ruby
|
108
|
+
link = client.link_detail('product_slug_goes_here')
|
109
|
+
#=> Instamojo Link(slug: product_slug_goes_here, title: Foo Bar, shorturl: http://imojo.in/ankurfoobar)
|
110
|
+
link.to_h
|
111
|
+
#=> {"title"=>"Foo Bar", "description"=>"", "slug"=>"foo-product", "shorturl"=>"http://imojo.in/ankurfoobar", "url"=>"https://www.instamojo.com/ankurgel/foo-product/", "cover_image"=> "https://www.filepicker.io/api/file/BHeefKAARCKGC5l1J29e/convert?w=500&h=500&fit=clip&quality=70", "currency"=>"INR", "base_price"=>"0.00", "quantity"=>nil, "quantity_sold"=>2, "requires_shipping"=>false, "ships_within_days"=>nil, "start_date"=>nil, "end_date"=>nil, "venue"=>"", "timezone"=>"", "note"=>"", "redirect_url"=>"", "webhook_url"=>"", "status"=>"Live", "enable_pwyw"=>false, "enable_sign"=>false, "socialpay_platforms"=>""}
|
112
|
+
```
|
113
|
+
|
114
|
+
#### Edit a product
|
115
|
+
```ruby
|
116
|
+
link = client.links_list.first
|
117
|
+
link.save do |l|
|
118
|
+
l.title = "Foo"
|
119
|
+
l.description = "This new information should go in product"
|
120
|
+
end
|
121
|
+
#=> Returns updated Link object from Instamojo
|
122
|
+
```
|
123
|
+
or
|
124
|
+
```ruby
|
125
|
+
link = client.link_detail('foo-product')
|
126
|
+
link.title = 'Foo'; link.description = 'This new information should go in product'
|
127
|
+
link.save
|
128
|
+
# returns updated Link object from Instamojo
|
129
|
+
```
|
130
|
+
or handle it directly without Link object
|
131
|
+
```ruby
|
132
|
+
client.edit_link({slug: 'foo-product', title: 'Foo', description: 'This new infromation should go in product'})
|
133
|
+
```
|
134
|
+
|
135
|
+
---
|
136
|
+
### Payments
|
137
|
+
`Payment` object contains the necessary information such as `payment_id`, `quantity`, `status`, `buyer_email` etc. Call `#to_h` on `payment` to get it's all attributes. `Payment` object has following helpers:
|
138
|
+
- `payment.to_h` - Returns equivalent Ruby hash for a payment
|
139
|
+
- `payment.to_json` - Returns equivalent JSON for a payment
|
140
|
+
- `payment.original` - Returns original payment data fetched from API.
|
141
|
+
- Like `Link`, it also exposes `reload` and `reload!`
|
142
|
+
|
143
|
+
Details are documented [here](https://www.instamojo.com/developers/rest/#toc-payments)
|
144
|
+
|
145
|
+
#### Get Payments
|
146
|
+
```ruby
|
147
|
+
client.payments_list
|
148
|
+
#=> Returns array of Payment objects
|
149
|
+
```
|
150
|
+
##### Supports optional pagination
|
151
|
+
```ruby
|
152
|
+
client.payments_list(page:1, limit:10)
|
153
|
+
#=> Array of 10 Payment objects (page 1)
|
154
|
+
```
|
155
|
+
#### Detail or status of a payment
|
156
|
+
```ruby
|
157
|
+
payment = client.payment_detail('MOJxxx06000F97367750')
|
158
|
+
#=> Instamojo Payment(payment_id: MOJxxx06000F97367750, quantity: 1, amount: 0.00, status: Credit, link_slug: api-product-7-node, buyer_name: Ankur Goel)
|
159
|
+
payment.to_h
|
160
|
+
#=> Hash of all payment object attributes
|
161
|
+
```
|
162
|
+
#### Request a payment
|
163
|
+
This is a part of [RAP API](https://www.instamojo.com/developers/request-a-payment-api/). You can request a payment from anyone via this who will then be notified to make a payment with specified payment. The payment then can be carried out via [Instapay](https://www.instamojo.com/pay/). Jump over to the documentation to see accepted parameters.
|
164
|
+
##### Code:
|
165
|
+
```ruby
|
166
|
+
payment_request = client.payment_request({amount:100, purpose: 'api', send_email: true, email: 'ankurgel+2@gmail.com', redirect_url: 'http://ankurgoel.com'})
|
167
|
+
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
|
168
|
+
```
|
169
|
+
#### Get Payment Requests
|
170
|
+
```ruby
|
171
|
+
payment_requests = client.payment_requests_list
|
172
|
+
#=> Returns array of PaymentRequest objects
|
173
|
+
```
|
174
|
+
##### Supports optional pagination
|
175
|
+
```ruby
|
176
|
+
client.payment_requests_list(page:1, limit:10)
|
177
|
+
#=> Array of 10 PaymentRequest objects (page 1)
|
178
|
+
```
|
179
|
+
#### Status of payment request
|
180
|
+
You can get the status of a payment_request from the id you obtained after making payment request.
|
181
|
+
```ruby
|
182
|
+
payment_request.reload!
|
183
|
+
#or
|
184
|
+
payment_request = client.payment_request_status('8726f8c5001e426f8b24e908b2761686')
|
185
|
+
#=> Instamojo PaymentRequest(id: 8726f8c5001e426f8b24e908b2761686, purpose: api, amount: 100.00, status: Sent, shorturl: http://imjo.in/Nasdf , longurl: https://www.instamojo.com/@ashwini/8726f8c5001e426f8b24e908b2761686)
|
186
|
+
```
|
187
|
+
---
|
188
|
+
### Refunds
|
189
|
+
`Refund` object contains the necessary information such as `payment_id`, `refund_amount`, `status` and `body` etc. Call `#to_h` on `refund` to get it's all attributes. `Refund` object has the same helpers as `Payment` above, including `reload` and `reload!`.
|
190
|
+
|
191
|
+
#### Get Refunds
|
192
|
+
```ruby
|
193
|
+
refunds = client.refunds_list
|
194
|
+
#=> Returns array of Refund objects
|
195
|
+
```
|
196
|
+
##### Supports optional pagination
|
197
|
+
```ruby
|
198
|
+
client.refunds_list(page:1, limit:10)
|
199
|
+
#=> Array of 10 Refund objects (page 1)
|
200
|
+
```
|
201
|
+
#### Create a new refund
|
202
|
+
##### Required:
|
203
|
+
* `payment_id` - Payment ID of the payment against which you're initiating the refund.
|
204
|
+
* `type` - A three letter short-code identifying the [reason for this case](https://www.instamojo.com/developers/rest/#toc-refunds).
|
205
|
+
* `body` - Additonal text explaining the refund.
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
client.create_refund({payment_id: 'MOJO5c04000J30502939', type: 'QFL', body: 'Customer is not satisfied'})
|
209
|
+
#=> Returns Refund object or non-200 response object
|
210
|
+
```
|
211
|
+
or
|
212
|
+
```ruby
|
213
|
+
client.create_refund do |refund|
|
214
|
+
refund.payment_id = 'MOJO5c04000J30502939'
|
215
|
+
refund.type = 'QFL'
|
216
|
+
refund.body = 'Customer is not satisifed'
|
217
|
+
end
|
218
|
+
```
|
219
|
+
or refund a `payment` directly:
|
220
|
+
```ruby
|
221
|
+
payment = client.payment_detail('MOJO5c05000F97367750')
|
222
|
+
payment.process_refund(type: 'QFL', body: 'User wanted different version') #or
|
223
|
+
payment.process_refund do |refund|
|
224
|
+
refund.type = 'QFL'
|
225
|
+
refund.body = 'User wanted different version'
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
#### Details of a refund
|
230
|
+
```ruby
|
231
|
+
refund = client.refund_detail 'C5c0751269'
|
232
|
+
#=> Instamojo Refund(id: C5c0751269, status: 'Refunded' payment_id: MOJO5c04000J30502939, refund_amount: 100)
|
233
|
+
refund.to_h
|
234
|
+
#=> Hash of all refund attributes
|
235
|
+
refund.reload!
|
236
|
+
#=> Updates the refund from server
|
237
|
+
#=> Instamojo Refund(id: C5c0751269, status: 'Closed' payment_id: MOJO5c04000J30502939, refund_amount: 100)
|
238
|
+
```
|
239
|
+
or
|
240
|
+
```ruby
|
241
|
+
refunds = client.refunds_list
|
242
|
+
refund = refunds.last
|
243
|
+
refund.reload #=> refetches the refund from server
|
244
|
+
#=> Instamojo Refund(id: C5c0751269, status: 'Refunded' payment_id: MOJO5c04000J30502939, refund_amount: 100)
|
245
|
+
```
|
246
|
+
|
247
|
+
---
|
248
|
+
### Authentication
|
249
|
+
```ruby
|
250
|
+
client.authenticate('instamojo_username', 'instamojo_password')
|
251
|
+
#or
|
252
|
+
client.authenticate do |user|
|
253
|
+
user.username = "instamojo_username"
|
254
|
+
user.password = "instamojo_password"
|
255
|
+
end
|
256
|
+
#=> Instamojo Client(URL: https://www.instamojo.com/api/1, Status: Authenticated)
|
257
|
+
```
|
258
|
+
#### Logout
|
259
|
+
```ruby
|
260
|
+
client.logout
|
261
|
+
```
|
262
|
+
---
|
263
|
+
### Misc
|
264
|
+
* `client.authorized` - View last status of api client request.
|
265
|
+
* `client.response` - View last procured response by client.
|
266
|
+
* `client.response.code` - View `response_code` of last request sent by client.
|
267
|
+
|
268
|
+
#### Logging
|
269
|
+
If you are interested in seeing api requests being made to Instamojo server. Flip this flag: `Instamojo::DEBUG = true` and genereate the api client again.
|
270
|
+
|
271
|
+
|
272
|
+
## Contributing
|
273
|
+
|
274
|
+
* [Fork](https://github.com/AnkurGel/Instamojo-rb/fork) the project
|
275
|
+
* `bundle install` to satisfy gem dependencies.
|
276
|
+
* `rake install` to install the gem.
|
277
|
+
* Swim around in `lib/`.
|
278
|
+
|
279
|
+
## Contributors
|
280
|
+
1. Ashwini Chaudhary - [@ashwch](https://github.com/ashwch)
|
281
|
+
* [PR #3](https://github.com/AnkurGel/Instamojo-rb/pull/3) - Couple of minor fixes.
|
282
|
+
* [PR #4](https://github.com/AnkurGel/Instamojo-rb/pull/4) - Class wrapper over Payment Request. Code fixes.
|
283
|
+
|
284
|
+
## Copyright
|
285
|
+
|
286
|
+
Copyright (c) 2014 Ankur Goel.
|
287
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
= Instamojo-rb
|
2
|
+
|
3
|
+
This is the *Ruby* library of {Instamojo API}[http://instamojo.com/developers].
|
4
|
+
This will assist you to programmatically create, edit and delete offers on Instamojo.
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
gem install Instamojo-rb
|
8
|
+
|
9
|
+
For Rails/bundler projects:
|
10
|
+
gem 'Instamojo-rb'
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
=== Set API keys
|
15
|
+
require 'Instamojo-rb'
|
16
|
+
api = Instamojo::API.new do |app|
|
17
|
+
app.app_id = "app_id-you-received-from-api@instamojo.com"
|
18
|
+
end
|
19
|
+
#or
|
20
|
+
api = Instamojo::API.new("app_id-you-received-from-api@instamojo.com")
|
21
|
+
|
22
|
+
=== Generate Client
|
23
|
+
client = api.client
|
24
|
+
|
25
|
+
=== Authentication
|
26
|
+
client.authenticate('instamojo_username', 'instamojo_password')
|
27
|
+
#or
|
28
|
+
client.authenticate do |user|
|
29
|
+
user.username = "instamojo_username"
|
30
|
+
user.password = "instamojo_password"
|
31
|
+
end
|
32
|
+
#=> Instamojo Client(URL: https://www.instamojo.com/api/1, Status: Authenticated)
|
33
|
+
|
34
|
+
=== Offers
|
35
|
+
|
36
|
+
==== List all offers
|
37
|
+
|
38
|
+
client.get_offers
|
39
|
+
|
40
|
+
==== List details of an offer
|
41
|
+
|
42
|
+
offer_slug = "my-foo-product"
|
43
|
+
client.get_offer(offer_slug)
|
44
|
+
#=> {"offer"=> {"shorturl"=>nil, "start_date"=>nil, "note"=>"", "description"=>"This is a demo product. Just *claim* it. ", "venue"=>nil, "title"=>"Demo product", "url"=>"https://www.instamojo.com/ankurgel/demo-product/", "slug"=>"demo-product", "base_price"=>"0.00", "quantity"=>nil, "end_date"=>nil, "currency"=>"INR", "cover_image"=>nil, "timezone"=>nil, "redirect_url"=>""},
|
45
|
+
|
46
|
+
==== Create an offer
|
47
|
+
|
48
|
+
client.create_offer do |offer|
|
49
|
+
offer.title = "Command line offer"
|
50
|
+
offer.description = "This offer is being created via Instamojo-rb"
|
51
|
+
offer.currency = "INR"
|
52
|
+
offer.base_price = 0
|
53
|
+
offer.quantity = 0
|
54
|
+
end
|
55
|
+
|
56
|
+
#OR
|
57
|
+
client.create_offer({
|
58
|
+
"title" => "Command line offer",
|
59
|
+
"description" => "This offer is being created via Instamojo-rb",
|
60
|
+
"currency" => "INR",
|
61
|
+
"base_price" => 0,
|
62
|
+
"quantity" => 0
|
63
|
+
})
|
64
|
+
|
65
|
+
==== Archive an offer
|
66
|
+
|
67
|
+
offer_slug = "my-foo-product"
|
68
|
+
client.delete_offer(offer_slug)
|
69
|
+
|
70
|
+
==== Logout
|
71
|
+
client.logout
|
72
|
+
|
73
|
+
|
74
|
+
== Development Pipeline
|
75
|
+
Few things which will be available in next versions:
|
76
|
+
|
77
|
+
* Error handling; with respect to `Instamojo` error codes.
|
78
|
+
* File Upload support.
|
79
|
+
* +Offer+ and +Event+ model with api methods like
|
80
|
+
* _Accessor_ methods like on +Offer+: +#title+, +#description+, +#quantity+
|
81
|
+
* Functional setters: +offer.set_title('Changed offer title')+
|
82
|
+
* +offer.set_quantity(30)+
|
83
|
+
* +offer.enable_variants+
|
84
|
+
|
85
|
+
|
86
|
+
== Copyright
|
87
|
+
|
88
|
+
Copyright (c) 2014 Ankur Goel. See LICENSE.txt for further details.
|
89
|
+
|