vncpost_api 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bab00738a4e65dfa53e1da95a9f93610686b232da184fb3195afc4aa765f16e
4
- data.tar.gz: debdaf9f7580a9b0752c843be16da364f5c3801e2bf33ab0f775bd4bd6ab5de6
3
+ metadata.gz: 4711251bf2f83d6f27bc258c6a9c7190ba56a3743d078ffe11b97725fe58c640
4
+ data.tar.gz: 0d0febd554898baf313c4bfec8e5924be1424906de0a35a818e9fe3dc4566331
5
5
  SHA512:
6
- metadata.gz: 6c8d8c3928889f31de818758a1c66e308f8cddf68075bb7f572aafb796eaba8bc060ec2b1cda661182ffafd0ad0bb5284b83ad3015eef5724a4402714aff9824
7
- data.tar.gz: 24ac04b1fe4e881359fd948a206fb9baf139fc0d6fccfbcfd0007b454110fe49940d546ffd6c286986be64671a9d307291ff45d452ae15f5d88bdb60d0735ac0
6
+ metadata.gz: 33a58c22000f60b09363337b5af981b7712722607b162e702a3ca1e3d8fe7d30a37c83a65a588b1d36d941cb0c848557bba536a23cd8f4f74189cebaccfb286c
7
+ data.tar.gz: cfe8e8dba531e438396b180c1ae0b4107aa095e77b561a5e1d31a100e371777b9765b1050705a5b12b8e6d3305a504bfa2f03b30c183bf23471a72695c66be0a
@@ -0,0 +1,47 @@
1
+ name: Rspec
2
+
3
+ on: [push]
4
+
5
+ env:
6
+ POSTGRES_USER: postgres
7
+ POSTGRES_PASSWORD: "postgres"
8
+ POSTGRES_DB: "postco_test"
9
+
10
+ jobs:
11
+ rspec:
12
+ name: Rspec
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: ["2.5", "2.6", "2.7"]
17
+ fail-fast: true
18
+ steps:
19
+ - name: Checkout to repo
20
+ uses: actions/checkout@master
21
+
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+
27
+ - name: Cache ruby gems
28
+ uses: actions/cache@v1
29
+ with:
30
+ path: vendor/bundle
31
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
32
+ restore-keys: |
33
+ ${{ runner.os }}-gems-
34
+
35
+ - name: Build gem
36
+ run: |
37
+ gem install bundler
38
+ bundle config path vendor/bundle
39
+ bundle install --jobs 4 --retry 3
40
+
41
+ - name: Run rspec tests
42
+ env:
43
+ VNCPOST_API_HOST: ${{secrets.VNCPOST_API_HOST}}
44
+ VNCPOST_USERNAME: ${{secrets.VNCPOST_USERNAME}}
45
+ VNCPOST_PASSWORD: ${{secrets.VNCPOST_PASSWORD}}
46
+ run: |
47
+ bundle exec rspec spec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # VNCPostAPI
2
2
 
3
+ ![Rspec](https://github.com/PostCo/vncpost_api/workflows/Rspec/badge.svg)
4
+
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vncpost_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
6
 
5
7
  TODO: Delete this and the text above, and describe your gem
data/bin/setup CHANGED
@@ -7,11 +7,9 @@ bundle install
7
7
 
8
8
  # Do any other automated setup that you need to do here
9
9
  filename=".env"
10
- if [ ! -f $filename ]
11
- then
10
+ if [ ! -f $filename ]; then
12
11
  touch $filename
13
- echo "VNCPOST_API_HOST=http://tu.api.vncpost.com" >> $filename
14
- echo "VNCPOST_USERNAME=postco" >> $filename
15
- echo "VNCPOST_PASSWORD=" >> $filename
16
- echo "VNCPostAPI_GEM_ENV=development" >> $filename
17
- fi
12
+ echo "VNCPOST_API_HOST=http://tu.api.vncpost.com" >>$filename
13
+ echo "VNCPOST_USERNAME=postco" >>$filename
14
+ echo "VNCPOST_PASSWORD=" >>$filename
15
+ fi
@@ -1,6 +1,6 @@
1
1
  def set_config
2
2
  VNCPostAPI.configure do |config|
3
- config.api_host = ENV["VNCPOST_API_HOST"]
3
+ config.testing = true
4
4
  config.username = ENV["VNCPOST_USERNAME"]
5
5
  config.password = ENV["VNCPOST_PASSWORD"]
6
6
  end
@@ -1,6 +1,7 @@
1
1
  module VNCPostAPI
2
2
  class Configuration
3
- attr_accessor :api_host, :username, :password
3
+ attr_accessor :testing, :username, :password
4
+ alias_method :testing?, :testing
4
5
  end
5
6
 
6
7
  def self.config
@@ -14,6 +15,12 @@ module VNCPostAPI
14
15
  def self.configure
15
16
  yield config
16
17
  # set the site once user configure
17
- VNCPostAPI::Base.site = VNCPostAPI.config.api_host
18
+ if config.testing?
19
+ VNCPostAPI::Base.site = "http://api.v3.vncpost.com"
20
+ VNCPostAPI::Tracking.site ="https://pt.v.vncpost.com"
21
+ else
22
+ VNCPostAPI::Base.site = "http://u.api.vncpost.com"
23
+ VNCPostAPI::Tracking.site = "https://pt.vncpost.com"
24
+ end
18
25
  end
19
26
  end
@@ -3,7 +3,6 @@ module VNCPostAPI
3
3
  self.include_root_in_json = false
4
4
  self.include_format_in_path = false
5
5
  self.connection_class = VNCPostAPI::Connection
6
- self.site = VNCPostAPI.config&.api_host
7
6
 
8
7
  def create
9
8
  self.class.retrieve_token
@@ -26,8 +25,9 @@ module VNCPostAPI
26
25
 
27
26
  def self.retrieve_token
28
27
  clear_auth_token
28
+
29
29
  if VNCPostAPI.config&.username && VNCPostAPI.config&.password
30
- response = connection.post("/User/Login", {
30
+ response = connection.post("#{Base.site}/User/Login", {
31
31
  Username: VNCPostAPI.config.username,
32
32
  Password: VNCPostAPI.config.password
33
33
  }.to_json)
@@ -44,16 +44,17 @@ module VNCPostAPI
44
44
  end
45
45
 
46
46
  def format_before_send_request
47
- @attributes.transform_keys!(&:camelcase)
47
+ @attributes.deep_transform_keys!(&:camelcase)
48
48
  end
49
49
 
50
50
  def reset_attributes_format
51
- @attributes.transform_keys!(&:underscore)
51
+ @attributes.deep_transform_keys!(&:underscore)
52
52
  end
53
53
 
54
54
  def load_attributes_from_response(response)
55
55
  super
56
56
  reset_attributes_format
57
57
  end
58
+
58
59
  end
59
60
  end
@@ -47,20 +47,14 @@ module VNCPostAPI
47
47
  self.prefix = "/Order/Add"
48
48
  self.element_name = ""
49
49
 
50
- def self.track(code)
51
- new(code: code).track
52
- end
53
-
54
50
  def initialize(attributes = {}, persisted = false)
55
51
  attributes = DEFAULT_ATTRS.merge(attributes)
56
52
  super
57
53
  end
58
54
 
59
55
  def track
60
- puts "#track only available in production environment"
61
- self.class.retrieve_token
62
56
  tracking_number = @attributes[:returned_code] || @attributes[:code]
63
- get("Track/#{tracking_number}")
57
+ Tracking.find(tracking_number)
64
58
  end
65
59
 
66
60
  private
@@ -0,0 +1,17 @@
1
+ module VNCPostAPI
2
+ class Tracking < Base
3
+ self.prefix = "/Track/Order"
4
+ self.element_name = ""
5
+
6
+ def self.find(code)
7
+ body = {
8
+ Code: code
9
+ }
10
+
11
+ self.retrieve_token
12
+
13
+ response = connection.post(collection_path, body.to_json)
14
+ new(self.format.decode(response.body).deep_transform_keys!(&:underscore))
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module VNCPostAPI
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vncpost_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-22 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".byebug_history"
91
+ - ".github/workflows/rspec.yml"
91
92
  - ".gitignore"
92
93
  - ".rspec"
93
94
  - ".travis.yml"
@@ -106,6 +107,7 @@ files:
106
107
  - lib/vncpost_api/connection.rb
107
108
  - lib/vncpost_api/resources/base.rb
108
109
  - lib/vncpost_api/resources/order.rb
110
+ - lib/vncpost_api/resources/tracking.rb
109
111
  - lib/vncpost_api/version.rb
110
112
  - vncpost_api.gemspec
111
113
  homepage: https://github.com/PostCo/vncpost_api
@@ -131,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  - !ruby/object:Gem::Version
132
134
  version: '0'
133
135
  requirements: []
134
- rubygems_version: 3.1.2
136
+ rubygems_version: 3.0.3
135
137
  signing_key:
136
138
  specification_version: 4
137
139
  summary: Ruby object based VNCPost API wrapper.