tiendanube-ruby 0.1.3

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: 616ab4f1c9bce0cae66da3fb7512ccde2afcd8a2
4
+ data.tar.gz: 4437dd19e8067d9bf47aea5894c9abdeb8ed470b
5
+ SHA512:
6
+ metadata.gz: 0699fcb6336483630d8db74fdbfaf761eafbd2001352bac314130a5d7909d9d36e9b1b1cce1d5fb27debc172d85d21a162be6d3c63e05cedba9a32f798a59769
7
+ data.tar.gz: 22111e3bb893d44e0e9064dcb9e63b65b96741748687fef7530823068be546e71704a2a79beb2ede6c5cc089ca3a565af54c482efe728dd85ef582352093731e
data/.gitignore ADDED
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tienda_nube.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Carlos Kozuszko
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,41 @@
1
+ # TiendaNube
2
+
3
+ Simple gem to provida a basic connection with the [TiendaNube API](https://github.com/tiendanube/api-docs) endpoints.
4
+
5
+ This gem is a fork of MIT licensed version created originaly by Diego de Estrada and Nicolás Bares.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tienda_nube'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tienda_nube
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tienda_nube. 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.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tienda_nube"
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
@@ -0,0 +1,15 @@
1
+ require 'net/https'
2
+ require 'json'
3
+
4
+ require "tienda_nube/version"
5
+ require 'tienda_nube/resource'
6
+ require 'tienda_nube/auth'
7
+
8
+ module TiendaNube
9
+ API_URL = 'https://api.tiendanube.com'
10
+ API_Version = 'v1'
11
+ class << self
12
+ attr_accessor :access_token, :client_id, :client_secret, :store_id, :language
13
+ end
14
+ self.language = 'es'
15
+ end
@@ -0,0 +1,42 @@
1
+ module TiendaNube
2
+ class Auth
3
+ class << self
4
+ attr_accessor :client_id, :client_secret
5
+ end
6
+ Auth_URL = { :ar => "https://www.tiendanube.com/apps",
7
+ :br => "https://www.nuvemshop.com.br/apps"}
8
+ def self.config
9
+ yield self
10
+ end
11
+ def initialize(country = :ar)
12
+ @client_id = Auth.client_id
13
+ @client_secret = Auth.client_secret
14
+ @country = country
15
+ end
16
+ def authorize_url
17
+ [Auth_URL[@country], @client_id, "authorize"].join("/")
18
+ end
19
+ def get_access_token(code)
20
+ params = {
21
+ :client_id => @client_id,
22
+ :client_secret => @client_secret,
23
+ :grant_type => 'authorization_code',
24
+ :code => code
25
+ }
26
+ uri = URI([Auth_URL[@country], 'authorize/token'].join('/'))
27
+ request = Net::HTTP.post_form(uri ,params)
28
+ if request.code != "200"
29
+ return {:error => "server error"}
30
+ else
31
+ json = JSON.parse(request.body)
32
+ if json["error_description"]
33
+ {:error => json["error_description"]}
34
+ else
35
+ { :store_id => json["user_id"],
36
+ :access_token => json["access_token"],
37
+ :scope => json["scope"] }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,113 @@
1
+ module TiendaNube
2
+ module Resource
3
+ class << self
4
+ attr_accessor :api_url, :api_version, :store_id, :access_token
5
+ end
6
+ self.api_url = 'https://api.tiendanube.com'
7
+ self.api_version = 'v1'
8
+ def self.config
9
+ yield self
10
+ end
11
+ def self.base_url
12
+ "#{self.api_url}/#{self.api_version}/#{self.store_id}"
13
+ end
14
+ def self.send_request(uri, request)
15
+ request['Authentication'] = "bearer #{self.access_token}"
16
+ request['Content-Type'] = "application/json"
17
+ response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
18
+ http.request request
19
+ end
20
+ result = {
21
+ :status => [response.code, response.message],
22
+ :headers => response.to_hash,
23
+ :body => JSON.parse(response.body)
24
+ }
25
+ if links = response["link"]
26
+ result[:pages] = links.split(", ").inject({}) do |hash, link|
27
+ array = link.split("; ")
28
+ hash[$1] = array[0].gsub(/^<(.*)>$/, '\1') if array[1].match(/rel=\"([a-z]+)\"/)
29
+ hash
30
+ end
31
+ end
32
+ return result
33
+ end
34
+ def self.uri(path)
35
+ unless (uri=URI(path)).absolute?
36
+ uri = URI(self.base_url)
37
+ uri.path = "/#{self.api_version}/#{self.store_id}/#{path}"
38
+ end
39
+ return uri
40
+ end
41
+ def self.get(path, query={})
42
+ uri = self.uri(path)
43
+ uri.query = URI.encode_www_form(query) unless query.empty?
44
+ request = Net::HTTP::Get.new uri
45
+ self.send_request(uri, request)
46
+ end
47
+ def self.delete(path)
48
+ uri = self.uri(path)
49
+ request = Net::HTTP::Delete.new uri
50
+ self.send_request(uri, request)
51
+ end
52
+ def self.post(path, data)
53
+ uri = self.uri(path)
54
+ request = Net::HTTP::Post.new uri
55
+ request.body = data.to_json
56
+ self.send_request(uri, request)
57
+ end
58
+ def self.put(path, data)
59
+ uri = self.uri(path)
60
+ request = Net::HTTP::Put.new uri
61
+ request.body = data.to_json
62
+ self.send_request(uri, request)
63
+ end
64
+ class Base
65
+ class << self
66
+ attr_accessor :name
67
+ end
68
+ def self.all(query={})
69
+ Resource.get(self.name, query)
70
+ end
71
+ def self.get(id)
72
+ Resource.get("#{self.name}/#{id}")
73
+ end
74
+ def self.delete(id)
75
+ Resource.delete("#{self.name}/#{id}")
76
+ end
77
+ def self.create(data)
78
+ Resource.post(self.name, data)
79
+ end
80
+ def self.update(id, data)
81
+ Resource.put("#{self.name}/#{id}", data)
82
+ end
83
+ def self.from_url(url)
84
+ Resource.get(url)
85
+ end
86
+ # class BaseDependant < Base
87
+ # def self.url(product_id, id=nil)
88
+ # end
89
+ end
90
+ end
91
+ class Store
92
+ def self.get
93
+ Resource.get('store')
94
+ end
95
+ end
96
+ class Product < Resource::Base
97
+ self.name = 'products'
98
+ end
99
+ class Category < Resource::Base
100
+ self.name = 'categories'
101
+ end
102
+ class ProductVariant < Resource::Base
103
+ class << self
104
+ attr_accessor :product_id
105
+ self.name = 'variants'
106
+ end
107
+ def self.url(id = nil)
108
+ url = "#{Resource.base_url}/products/#{self.product_id}/#{self.name}"
109
+ url = "#{url}/#{id}" if id
110
+ return url
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ module TiendaNube
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tienda_nube/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tiendanube-ruby"
8
+ spec.version = TiendaNube::VERSION
9
+ spec.authors = ["Carlos Kozuszko"]
10
+ spec.email = ["carlos@insignia4u.com"]
11
+
12
+ spec.summary = %q{Simple gem to connect with the TiendaNube API.}
13
+ spec.description = %q{Simple gem to provida a basic connection with the TiendaNube API endpoints.}
14
+ spec.homepage = "https://github.com/boxupgo/tiendanube-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "json", "~> 1.8"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiendanube-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Kozuszko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Simple gem to provida a basic connection with the TiendaNube API endpoints.
56
+ email:
57
+ - carlos@insignia4u.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/tienda_nube.rb
70
+ - lib/tienda_nube/auth.rb
71
+ - lib/tienda_nube/resource.rb
72
+ - lib/tienda_nube/version.rb
73
+ - tienda_nube.gemspec
74
+ homepage: https://github.com/boxupgo/tiendanube-ruby
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.5.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Simple gem to connect with the TiendaNube API.
98
+ test_files: []