Instamojo-rb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +20 -0
- data/README.md +99 -0
- data/README.rdoc +89 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/API/api.rb +25 -0
- data/lib/Instamojo-rb.rb +12 -0
- data/lib/client/client.rb +168 -0
- data/lib/utility.rb +15 -0
- data/spec/Instamojo-rb_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +164 -0
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
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "jeweler", "~> 1.8.7"
|
13
|
+
gem "faraday", "0.8.8"
|
14
|
+
gem "debugger"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
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
|
+
faraday (0.8.8)
|
15
|
+
multipart-post (~> 1.2.0)
|
16
|
+
git (1.2.6)
|
17
|
+
github_api (0.10.1)
|
18
|
+
addressable
|
19
|
+
faraday (~> 0.8.1)
|
20
|
+
hashie (>= 1.2)
|
21
|
+
multi_json (~> 1.4)
|
22
|
+
nokogiri (~> 1.5.2)
|
23
|
+
oauth2
|
24
|
+
hashie (2.0.5)
|
25
|
+
highline (1.6.20)
|
26
|
+
httpauth (0.2.0)
|
27
|
+
jeweler (1.8.8)
|
28
|
+
builder
|
29
|
+
bundler (~> 1.0)
|
30
|
+
git (>= 1.2.5)
|
31
|
+
github_api (= 0.10.1)
|
32
|
+
highline (>= 1.6.15)
|
33
|
+
nokogiri (= 1.5.10)
|
34
|
+
rake
|
35
|
+
rdoc
|
36
|
+
json (1.8.1)
|
37
|
+
jwt (0.1.8)
|
38
|
+
multi_json (>= 1.5)
|
39
|
+
multi_json (1.8.2)
|
40
|
+
multi_xml (0.5.5)
|
41
|
+
multipart-post (1.2.0)
|
42
|
+
nokogiri (1.5.10)
|
43
|
+
oauth2 (0.9.2)
|
44
|
+
faraday (~> 0.8)
|
45
|
+
httpauth (~> 0.2)
|
46
|
+
jwt (~> 0.1.4)
|
47
|
+
multi_json (~> 1.0)
|
48
|
+
multi_xml (~> 0.5)
|
49
|
+
rack (~> 1.2)
|
50
|
+
rack (1.5.2)
|
51
|
+
rake (10.1.1)
|
52
|
+
rdoc (3.12.2)
|
53
|
+
json (~> 1.4)
|
54
|
+
rspec (2.8.0)
|
55
|
+
rspec-core (~> 2.8.0)
|
56
|
+
rspec-expectations (~> 2.8.0)
|
57
|
+
rspec-mocks (~> 2.8.0)
|
58
|
+
rspec-core (2.8.0)
|
59
|
+
rspec-expectations (2.8.0)
|
60
|
+
diff-lcs (~> 1.1.2)
|
61
|
+
rspec-mocks (2.8.0)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
bundler (~> 1.0)
|
68
|
+
debugger
|
69
|
+
faraday (= 0.8.8)
|
70
|
+
jeweler (~> 1.8.7)
|
71
|
+
rdoc (~> 3.12)
|
72
|
+
rspec (~> 2.8.0)
|
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,99 @@
|
|
1
|
+
#Instamojo-rb#
|
2
|
+
This is the **Ruby** library of [Instamojo API](http://instamojo.com/developers).
|
3
|
+
This will assist you to programmatically create, edit and delete offers on Instamojo.
|
4
|
+
|
5
|
+
##Installation##
|
6
|
+
`gem install Instamojo-rb`
|
7
|
+
|
8
|
+
For your Rails/bundler projects:
|
9
|
+
`gem 'Instamojo-rb'`
|
10
|
+
|
11
|
+
##Usage##
|
12
|
+
|
13
|
+
###Set API keys###
|
14
|
+
```ruby
|
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
|
+
|
23
|
+
###Generate client:###
|
24
|
+
`client = api.client`
|
25
|
+
|
26
|
+
###Authentication###
|
27
|
+
```ruby
|
28
|
+
client.authenticate('instamojo_username', 'instamojo_password')
|
29
|
+
#or
|
30
|
+
client.authenticate do |user|
|
31
|
+
user.username = "instamojo_username"
|
32
|
+
user.password = "instamojo_password"
|
33
|
+
end
|
34
|
+
#=> Instamojo Client(URL: https://www.instamojo.com/api/1, Status: Authenticated)
|
35
|
+
```
|
36
|
+
|
37
|
+
###Offers###
|
38
|
+
####List all offers####
|
39
|
+
`client.get_offers`
|
40
|
+
|
41
|
+
####List details of an offer####
|
42
|
+
**Syntax:** `client.get_offer(offer_slug)`
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
client.get_offer('demo-product')
|
46
|
+
#=> {"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"=>""},
|
47
|
+
# "success"=>true}
|
48
|
+
```
|
49
|
+
|
50
|
+
####Create an offer####
|
51
|
+
```ruby
|
52
|
+
client.create_offer do |offer|
|
53
|
+
offer.title = "Command line offer"
|
54
|
+
offer.description = "This offer is being created via Instamojo-rb"
|
55
|
+
offer.currency = "INR"
|
56
|
+
offer.base_price = 0
|
57
|
+
offer.quantity = 0
|
58
|
+
end
|
59
|
+
|
60
|
+
#OR
|
61
|
+
client.create_offer({
|
62
|
+
"title" => "Command line offer",
|
63
|
+
"description" => "This offer is being created via Instamojo-rb",
|
64
|
+
"currency" => "INR",
|
65
|
+
"base_price" => 0,
|
66
|
+
"quantity" => 0
|
67
|
+
})
|
68
|
+
```
|
69
|
+
|
70
|
+
####Archive an offer####
|
71
|
+
`client.delete_offer('demo-product')`
|
72
|
+
|
73
|
+
###Logout###
|
74
|
+
`client.logout`
|
75
|
+
|
76
|
+
|
77
|
+
##Development pipeline##
|
78
|
+
|
79
|
+
Few things which will be available in next versions:
|
80
|
+
|
81
|
+
* Error handling; with respect to `Instamojo` error codes.
|
82
|
+
* File Upload support.
|
83
|
+
* `Offer` and `Event` model with api methods like
|
84
|
+
+ _Accessor_ methods like on `Offer`: `#title`, `#description`, `#quantity`
|
85
|
+
+ `offer.set_title('Changed offer title')`
|
86
|
+
+ `offer.set_quantity(30)`
|
87
|
+
+ `offer.enable_variants`
|
88
|
+
|
89
|
+
##Contributing##
|
90
|
+
|
91
|
+
* [Fork](https://github.com/AnkurGel/Instamojo-rb/fork) the project
|
92
|
+
* `bundle install` to satisfy gem dependencies.
|
93
|
+
* `rake install` to install the gem.
|
94
|
+
* Swim around in `lib/`.
|
95
|
+
|
96
|
+
##Copyright##
|
97
|
+
|
98
|
+
Copyright (c) 2014 Ankur Goel.
|
99
|
+
|
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
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "Instamojo-rb"
|
18
|
+
gem.homepage = "http://github.com/AnkurGel/Instamojo-rb"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo}
|
21
|
+
gem.description = %Q{Instamojo Ruby library - Assists you to programmatically create, edit and delete offers on Instamojo}
|
22
|
+
gem.email = "ankurgel@gmail.com"
|
23
|
+
gem.authors = ["Ankur Goel"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "Instamojo-rb #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/API/api.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Instamojo
|
2
|
+
class API
|
3
|
+
attr_accessor :app_id
|
4
|
+
|
5
|
+
def initialize(app_id = nil, options = {})
|
6
|
+
options = app_id if app_id.is_a? Hash
|
7
|
+
|
8
|
+
@app_id = app_id
|
9
|
+
|
10
|
+
options.each do |key, value|
|
11
|
+
instance_variable_set("@#{key}", value)
|
12
|
+
end
|
13
|
+
|
14
|
+
yield self if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
Instamojo::Client.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
sprintf("Instamojo API(key: %s)", @app_id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/Instamojo-rb.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
module Instamojo
|
2
|
+
class Client
|
3
|
+
attr_reader :connection_options, :app_id
|
4
|
+
attr_reader :request, :response
|
5
|
+
attr_reader :authentication_flag
|
6
|
+
|
7
|
+
def connection_options
|
8
|
+
@connection_options = lambda do |connection|
|
9
|
+
connection.request :url_encoded
|
10
|
+
connection.response :logger
|
11
|
+
connection.adapter Faraday.default_adapter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(api)
|
16
|
+
@conn = Faraday.new(Instamojo::URL, &connection_options)
|
17
|
+
|
18
|
+
#TODO: To abstract in /errors.rb
|
19
|
+
raise "Supply API with app_id before generating client" unless api.app_id
|
20
|
+
|
21
|
+
@app_id = api.app_id
|
22
|
+
add_header("X-App-Id", @app_id)
|
23
|
+
@authentication_flag = "Not authenticated"
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_connection_object
|
27
|
+
@conn #Faraday::Connection object
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def self.define_http_verb(http_verb)
|
32
|
+
define_method http_verb do |*args|
|
33
|
+
request = args[0] || "/"
|
34
|
+
params = args[1] || {}
|
35
|
+
|
36
|
+
@request = request
|
37
|
+
sanitize_request
|
38
|
+
method = @conn.method(http_verb)
|
39
|
+
@response = method.call(Instamojo::PREFIX + @request, params)
|
40
|
+
return sanitize_response
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
define_http_verb :get
|
45
|
+
define_http_verb :post
|
46
|
+
define_http_verb :patch
|
47
|
+
define_http_verb :delete
|
48
|
+
|
49
|
+
|
50
|
+
#POST /auth/
|
51
|
+
#Authenticate, generate token and add header
|
52
|
+
def authenticate(username = nil, password = nil, options = {}, &block)
|
53
|
+
if username.is_a?(Hash) or password.is_a?(Hash)
|
54
|
+
options = username.is_a?(Hash) ? username : password
|
55
|
+
end
|
56
|
+
options["username"] = username if username and !username.is_a?Hash
|
57
|
+
options["password"] = password if password and !password.is_a?Hash
|
58
|
+
|
59
|
+
options = set_options(options, &block)
|
60
|
+
|
61
|
+
#TODO: Raise error if doesn't find username and password key in options
|
62
|
+
@response = post('auth', options)
|
63
|
+
if @response.has_key?("success") and @response['success']
|
64
|
+
add_header("X-Auth-Token", @response['token'])
|
65
|
+
end
|
66
|
+
@response
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
#GET /offer - List all offers
|
71
|
+
def get_offers
|
72
|
+
unless get_connection_object.headers.has_key?("X-Auth-Token")
|
73
|
+
raise "Please authenticate() to see your offers"
|
74
|
+
end
|
75
|
+
get('offer')
|
76
|
+
end
|
77
|
+
|
78
|
+
#GET /offer/:slug
|
79
|
+
def get_offer(slug)
|
80
|
+
get("offer/#{slug}")
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
#POST /offer/ - Create an offer
|
85
|
+
def create_offer(options = {}, &block)
|
86
|
+
options = set_options(options, &block)
|
87
|
+
@response = post('offer', options)
|
88
|
+
end
|
89
|
+
|
90
|
+
#PATCH /offer/
|
91
|
+
def edit_offer(slug, options = {}, &block)
|
92
|
+
options = set_options(options, &block)
|
93
|
+
patch("/offer/#{slug}", options)
|
94
|
+
end
|
95
|
+
|
96
|
+
#DELETE /offer/:slug - Archives an offer
|
97
|
+
def delete_offer(slug)
|
98
|
+
unless get_connection_object.headers.has_key?("X-Auth-Token")
|
99
|
+
raise "Please authenticate() to see your offers"
|
100
|
+
end
|
101
|
+
delete("/offer/#{slug}")
|
102
|
+
end
|
103
|
+
|
104
|
+
#Uploading file and cover images
|
105
|
+
def upload_file
|
106
|
+
#TODO
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
#DELETE /auth/:token - Delete auth token
|
111
|
+
def logout
|
112
|
+
auth_token = get_connection_object.headers['X-Auth-Token']
|
113
|
+
raise "Can't find any authorization token to logout." unless auth_token
|
114
|
+
delete("/auth/#{auth_token}")
|
115
|
+
if @response.has_key?("success") and @response['success']
|
116
|
+
get_connection_object.headers.delete("X-Auth-Token")
|
117
|
+
end
|
118
|
+
@response
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
sprintf("Instamojo Client(URL: %s, Status: %s)",
|
124
|
+
Instamojo::URL + Instamojo::PREFIX,
|
125
|
+
@authentication_flag
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
private
|
131
|
+
def sanitize_request
|
132
|
+
@request.concat('/') unless request.end_with? "/"
|
133
|
+
@request.prepend('/') unless request.start_with? "/"
|
134
|
+
end
|
135
|
+
|
136
|
+
def sanitize_response
|
137
|
+
if @response.status == 200
|
138
|
+
@authentication_flag = "Authenticated"
|
139
|
+
JSON.parse(@response.body)
|
140
|
+
else
|
141
|
+
begin
|
142
|
+
({:client_error => "Something went wrong",
|
143
|
+
:response_code => @response.status
|
144
|
+
}).merge(JSON.parse(@response.body))
|
145
|
+
rescue JSON::ParserError
|
146
|
+
{:response_code => @response.status}
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def set_options(options, &block)
|
152
|
+
if block_given?
|
153
|
+
block_params = OpenStruct.new
|
154
|
+
block.call(block_params)
|
155
|
+
options = options.merge(block_params.marshal_dump)
|
156
|
+
end
|
157
|
+
#to tackle collective hash like:
|
158
|
+
#{"username" => "foo", :username => "foo"}
|
159
|
+
#added non-recursive basic code in lib/utility.rb
|
160
|
+
options.symbolize_keys!
|
161
|
+
end
|
162
|
+
|
163
|
+
def add_header(key, value)
|
164
|
+
previous_headers = get_connection_object.headers
|
165
|
+
get_connection_object.headers = previous_headers.merge({key => value})
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/lib/utility.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'Instamojo-rb'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Instamojo-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ankur Goel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
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.0'
|
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.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.7
|
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: 1.8.7
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: faraday
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.8.8
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - '='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.8.8
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: debugger
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Instamojo Ruby library - Assists you to programmatically create, edit
|
111
|
+
and delete offers on Instamojo
|
112
|
+
email: ankurgel@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- README.rdoc
|
119
|
+
files:
|
120
|
+
- .document
|
121
|
+
- .rspec
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- README.rdoc
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- lib/API/api.rb
|
130
|
+
- lib/Instamojo-rb.rb
|
131
|
+
- lib/client/client.rb
|
132
|
+
- lib/utility.rb
|
133
|
+
- spec/Instamojo-rb_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
homepage: http://github.com/AnkurGel/Instamojo-rb
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
hash: -260583537
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.8.23
|
160
|
+
signing_key:
|
161
|
+
specification_version: 3
|
162
|
+
summary: Instamojo Ruby library - Assists you to programmatically create, edit and
|
163
|
+
delete offers on Instamojo
|
164
|
+
test_files: []
|