snapdeal_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzRhMzAyYzY5OGI2ZjdlNTg1NWYwZjIyMTE2YWFiZmJlZjU5NTQ2Mw==
5
+ data.tar.gz: !binary |-
6
+ NGFkOWRjYzI5ZTRkNTA0NzEyNzczMjYzYmVmNTAwMGM2ZDNhN2ZiYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Zjk2NTdjODIyMDIxZjZlNmQ3NGYzZWEzNDExYmU2ZDY2MmQzNjAwZGZkZDlj
10
+ OWFlNTZjMTU0YzAzODE4Y2JmMmE1ZjIwNWRkNGQzNDk1YTAyY2MxNDM5MWM2
11
+ ZGY3ZjcxMWJhMGNjMTViM2FkY2NmOGRjZmQxYzVhNDJkNmQ5NDg=
12
+ data.tar.gz: !binary |-
13
+ ZjM1ZmI4ZTQzYjgzMGU4NzdjNjJjNmM0NDY4ODExMTE0ZGRkYzNhODY5Y2Nl
14
+ YjVhMTA2NGEwZTE1YTdhZmMxOTFmMGE5NjQ0YmZmZjZhYjc2NTUzZDA4NTQ4
15
+ N2NmZjJiNTgwNDVmODdiZmQzNzM0MjhjMmQ5ZjhjNzU4YjhlOTY=
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p551@snapdeal_api"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.26.11 (latest)" # 1.10.1 seems like a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)\n" # show the user the ruby and gemset they are using in green
37
+ else printf "%b" "Using: $GEM_HOME\n" # don't use colors in non-interactive shells
38
+ fi
39
+ fi
40
+ else
41
+ # If the environment file has not yet been created, use the RVM CLI to select.
42
+ rvm --create "$environment_id" || {
43
+ echo "Failed to create RVM environment '${environment_id}'."
44
+ return 1
45
+ }
46
+ fi
47
+
48
+ # If you use bundler, this might be useful to you:
49
+ # if [[ -s Gemfile ]] && {
50
+ # ! builtin command -v bundle >/dev/null ||
51
+ # builtin command -v bundle | GREP_OPTIONS="" \command \grep $rvm_path/bin/bundle >/dev/null
52
+ # }
53
+ # then
54
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
55
+ # gem install bundler
56
+ # fi
57
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
58
+ # then
59
+ # bundle install | GREP_OPTIONS="" \command \grep -vE '^Using|Your bundle is complete'
60
+ # fi
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in snapdeal_api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Girish
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.
@@ -0,0 +1,45 @@
1
+ # SnapdealApi
2
+
3
+ Utility class to pull data from snapdeal.com using Snapdeal's affiliate APIs http://affiliate.snapdeal.com/affiliate/api/product/feeds/.
4
+
5
+ Inspired by https://github.com/deepakhb2/flipkart_api
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'snapdeal_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install snapdeal_api
22
+
23
+ ## Usage
24
+
25
+ require 'snapdeal_api'
26
+
27
+ sd_api = SnapdealApi.new(Snapdeal-Affiliate-Id, Snapdeal-Token-Id, format) #format : json/xml
28
+
29
+ categories_string = sd_api.get_categories(optional format) #format : json/xml is optional, if not passed will use the one from new
30
+
31
+ categories = sd_api.get_parsed_categories
32
+
33
+ rest_url = sd_api.get_products_api(category_name) #Name is as present in the categories
34
+
35
+ products_string = sd_api.get_products_by_category(category_name) #Name is as present in categories. Returns upto first 500 products in the format specified while creating new object
36
+
37
+ products_string = sd_api.get_products(rest_url, optional format) #format : json/xml, if not passed will use the one from new
38
+
39
+ products_array = sd_api.get_all_products(rest_url) This method will fetch all the products in this category, in an array of JSON data. Warning: This implemenation is for reference, handle with care
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
@@ -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
@@ -0,0 +1,106 @@
1
+ require "snapdeal_api/version"
2
+
3
+ require "rest-client"
4
+ require "json"
5
+ require "nokogiri"
6
+
7
+ class SnapdealApi
8
+
9
+ # Initialise object with affiliate id, token and format to send api calls
10
+ def initialize(sd_affiliate_id, sd_affiliate_token, format="json")
11
+ @api = "http://affiliate-feeds.snapdeal.com/feed/#{sd_affiliate_id}"
12
+ @header = {"Snapdeal-Affiliate-Id" => sd_affiliate_id, "Snapdeal-Token-Id" => sd_affiliate_token}
13
+ @format = format
14
+ @categories = {} #cache: avoid subsequent requests
15
+ @parsed_categories = {}
16
+ @version = "v1"
17
+ end
18
+
19
+ # Get all the categories list, in xml/json format
20
+ def get_categories(format = nil)
21
+ ext = format.nil? ? @format : format
22
+ rest_url="#{@api}.#{ext}"
23
+ @categories = RestClient.get rest_url
24
+ end
25
+
26
+ # Get all the categories list, as key=>value pair
27
+ def get_parsed_categories
28
+ if @categories.empty?
29
+ get_categories
30
+ end
31
+ set_parsed_categories(@categories)
32
+ return @parsed_categories
33
+ end
34
+
35
+ def set_parsed_categories(categories)
36
+ if categories.start_with? "{"
37
+ @parsed_categories = parse_json categories
38
+ elsif categories.start_with? "<?xml"
39
+ @parsed_categories = parse_xml categories
40
+ else
41
+ raise "Wrong categories format, can't parse"
42
+ end
43
+ end
44
+
45
+ def parse_json(categories)
46
+ cats = JSON.parse(categories)
47
+ categories_hash = {}
48
+ cats['apiGroups']['Affiliate']['listingsAvailable'].each do |k,v|
49
+ categories_hash[k] = v['listingVersions'][@version]['get']
50
+ end
51
+ return categories_hash
52
+ end
53
+
54
+ def parse_xml(categories)
55
+ categories_hash = {}
56
+ @doc = Nokogiri::XML(categories)
57
+ @doc.xpath("//groupListings/apiGroups/entry/value/listingsAvailable/entry").each do |list|
58
+ if list.xpath("value/listingVersions/entry/key").text == @version
59
+ categories_hash[list.xpath("key").text] = list.xpath("value/listingVersions/entry/value/get").text
60
+ end
61
+ end
62
+ return categories_hash
63
+ end
64
+
65
+ #Get the rest api url for the given category name
66
+ def get_products_api(category)
67
+ if @parsed_categories.empty?
68
+ get_parsed_categories
69
+ end
70
+ @parsed_categories[category]
71
+ end
72
+
73
+ #Get the first 500 products from the category name
74
+ #Output will also contain "nextUrl" which inturn returns next 500 products.
75
+ def get_products_by_category(category)
76
+ get_products(get_products_api(category))
77
+ end
78
+
79
+ #Get the products from given rest url
80
+ def get_products(rest_url, format = nil)
81
+ format = format.nil? ? @format : format
82
+ header = @header
83
+ if format == "json" || format == "xml"
84
+ header['Accept'] = "application/#{format}"
85
+ else
86
+ raise "Wrong format: #{format} provided"
87
+ end
88
+
89
+ rest_output = RestClient.get rest_url, header
90
+ end
91
+
92
+ #Get all the products from given rest url
93
+ #returns an array of products
94
+ def get_all_products(rest_url)
95
+ json_arr = []
96
+ json_data = JSON.parse(get_products(rest_url, "json"))
97
+ json_arr << [json_data]
98
+ while json_data["nextUrl"]
99
+ json_data = JSON.parse(get_products(json_data["nextUrl"], "json"))
100
+ json_arr << [json_data]
101
+ break
102
+ end
103
+ jsonout = json_arr
104
+ end
105
+
106
+ end
@@ -0,0 +1,3 @@
1
+ class SnapdealApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -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 'snapdeal_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "snapdeal_api"
8
+ spec.version = SnapdealApi::VERSION
9
+ spec.authors = ["Girish Nair"]
10
+ spec.email = ["girish@girishn.com"]
11
+
12
+ spec.summary = %q{Pull data from snapdeal.com affiliate APIs}
13
+ spec.description = %q{This gem provides a simple utility class to pull data from snapdeal.com using Snapdeal's affiliate APIs}
14
+ spec.homepage = "https://rubygems.org/gems/snapdeal_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+
26
+ spec.add_dependency('rest-client', '1.7.2')
27
+ spec.add_dependency('nokogiri', '1.6.6.2')
28
+ spec.add_dependency('json', '1.8.1')
29
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snapdeal_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Girish Nair
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-13 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.7.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.6.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.6.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.1
97
+ description: This gem provides a simple utility class to pull data from snapdeal.com
98
+ using Snapdeal's affiliate APIs
99
+ email:
100
+ - girish@girishn.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .rvmrc
108
+ - .travis.yml
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/snapdeal_api.rb
114
+ - lib/snapdeal_api/version.rb
115
+ - snapdeal_api.gemspec
116
+ homepage: https://rubygems.org/gems/snapdeal_api
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.8
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Pull data from snapdeal.com affiliate APIs
140
+ test_files: []