wispro 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47ce815181ed121450b9e1ff86dfa9c3d0b5647b0f8797671d07a1adc5ebdf11
4
- data.tar.gz: eb9eba4a83c7708ef4d3b31cc21ed11e4150c2331f116bdc314c5c9c9ea78a81
3
+ metadata.gz: e1de28c95b76713ac252daadaba569bd333e64c73db0baa0bd3c54ab6168427d
4
+ data.tar.gz: 77f1585199ec650177be3f4ac5450495dc1b1a3792805b0019d0a86910afcdff
5
5
  SHA512:
6
- metadata.gz: 3021232f76c36d341dcc58b9abd6dd718545896b93df0722440b8a91c23131023711b4bfd88e89959cb3927e588b616cb45b3d3a54b349f8087d3a196966c1fd
7
- data.tar.gz: 9cf8cd95af379aa2548206e92d24e772901b977599fb9013711334f3f5ba39e86c6c4414489e2c29bb234b5d66e35370c32980993e0d237818a4f4fe5d975d2b
6
+ metadata.gz: a3994ca18b86ea8b835ccdfbbcbae8a155ae2f7d3942119a8edb00f6682f1c4daad49945918afb6f3ff67479854df82b9066c76d0f6fcd70a4aa8a639607e645
7
+ data.tar.gz: e6ab2a46bad3dc14b42e5b8a792eddf3a80b7102940dcaa8f57de79a94fdddd66fe042ddef4aec7d1e38fa6ff5f47fad722e7e018c7f2c7db24cdecddd8a978b
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,15 @@
1
+ image: "ruby:2.5"
2
+
3
+ before_script:
4
+ - ruby -v
5
+ - which ruby
6
+ - gem install bundler --no-document
7
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
8
+
9
+ rubocop:
10
+ script:
11
+ - bundle exec rubocop
12
+
13
+ rspec:
14
+ script:
15
+ - bundle exec rspec
data/.rubocop.yml CHANGED
@@ -33,3 +33,19 @@ Style/ClassAndModuleChildren:
33
33
 
34
34
  Style/MixinUsage:
35
35
  Enabled: false
36
+
37
+ Metrics/BlockLength:
38
+ Enabled: false
39
+
40
+ Metrics/LineLength:
41
+ Max: 100
42
+
43
+ Metrics/MethodLength:
44
+ Max: 50
45
+
46
+ Style/AlignHash:
47
+ Description: "Align the elements of a hash literal if they span more than one line."
48
+ Enabled: true
49
+ EnforcedHashRocketStyle: table
50
+ EnforcedColonStyle: table
51
+
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Wispro
2
2
 
3
- 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/wispro`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![GitLab CI](https://gitlab.com/mool/wispro/badges/master/pipeline.svg)](https://gitlab.com/mool/wispro/pipelines)
4
+ ![MIT License](https://img.shields.io/github/license/mool/wispro.svg)
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ Wispro Cloud API Client.
6
7
 
7
8
  ## Installation
8
9
 
@@ -22,17 +23,28 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ ```ruby
27
+ require 'wispro'
28
+
29
+ client = Wispro::Client.new('super-secret-token')
30
+ contracts = client.contracts
31
+ ```
26
32
 
27
33
  ## Development
28
34
 
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.
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can
36
+ also run `bin/console` for an interactive prompt that will allow you to
37
+ experiment.
30
38
 
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).
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To
40
+ release a new version, update the version number in `version.rb`, and then run
41
+ `bundle exec rake release`, which will create a git tag for the version, push
42
+ git commits and tags, and push the `.gem` file to
43
+ [rubygems.org](https://rubygems.org).
32
44
 
33
45
  ## Contributing
34
46
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wispro.
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mool/wispro.
36
48
 
37
49
  ## License
38
50
 
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
- task default: :spec
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RuboCop::RakeTask.new
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :tests
9
+ task tests: %i[rubocop spec]
data/lib/wispro/client.rb CHANGED
@@ -3,19 +3,31 @@ module Wispro
3
3
  include HTTParty
4
4
  base_uri 'https://www.cloud.wispro.co/api/v1'
5
5
 
6
+ PAGINATED_MODELS = {
7
+ bmus: :bmu,
8
+ clients: :client,
9
+ contracts: :contract,
10
+ coverages: :coverage,
11
+ mikrotiks: :mikrotik,
12
+ nodes: :node,
13
+ plans: :plan
14
+ }.freeze
15
+
6
16
  def initialize(token)
7
17
  @options = { headers: { 'Authorization' => token } }
8
18
  end
9
19
 
10
- def clients
11
- fetch_paginated_data('/clients')
12
- end
20
+ PAGINATED_MODELS.each do |plural, singular|
21
+ define_method plural do |&block|
22
+ fetch_paginated_data("/#{plural}") { |rows| block&.call(rows) }
23
+ end
13
24
 
14
- def client(id)
15
- req = fetch_data("/clients/#{id}")
16
- return false unless req['status'] == 200
25
+ define_method singular do |id|
26
+ req = fetch_data("/#{plural}/#{id}")
27
+ return false unless req['status'] == 200
17
28
 
18
- req['data']
29
+ req['data']
30
+ end
19
31
  end
20
32
 
21
33
  def update_client(id, data)
@@ -25,17 +37,6 @@ module Wispro
25
37
  req['data']
26
38
  end
27
39
 
28
- def contracts
29
- fetch_paginated_data('/contracts')
30
- end
31
-
32
- def contract(id)
33
- req = fetch_data("/contracts/#{id}")
34
- return false unless req['status'] == 200
35
-
36
- req['data']
37
- end
38
-
39
40
  def update_contract(id, data)
40
41
  req = update_data("/contracts/#{id}", body: data)
41
42
  return false unless req['status'] == 200
@@ -43,17 +44,6 @@ module Wispro
43
44
  req['data']
44
45
  end
45
46
 
46
- def plans
47
- fetch_paginated_data('/plans')
48
- end
49
-
50
- def plan(id)
51
- req = fetch_data("/plans/#{id}")
52
- return false unless req['status'] == 200
53
-
54
- req['data']
55
- end
56
-
57
47
  def update_plan(id, data)
58
48
  req = update_data("/plans/#{id}", body: data)
59
49
  return false unless req['status'] == 200
@@ -61,28 +51,6 @@ module Wispro
61
51
  req['data']
62
52
  end
63
53
 
64
- def bmus
65
- fetch_paginated_data('/bmus')
66
- end
67
-
68
- def bmu(id)
69
- req = fetch_data("/bmus/#{id}")
70
- return false unless req['status'] == 200
71
-
72
- req['data']
73
- end
74
-
75
- def mikrotiks
76
- fetch_paginated_data('/mikrotiks')
77
- end
78
-
79
- def mikrotik(id)
80
- req = fetch_data("/mikrotiks/#{id}")
81
- return false unless req['status'] == 200
82
-
83
- req['data']
84
- end
85
-
86
54
  private
87
55
 
88
56
  def fetch_data(path, parameters = {})
@@ -99,6 +67,8 @@ module Wispro
99
67
  req = fetch_data(path, query: { page: page })
100
68
  break unless req['status'] == 200
101
69
 
70
+ yield req['data'] if block_given?
71
+
102
72
  results.concat(req['data'])
103
73
 
104
74
  break if page == req['meta']['pagination']['total_pages']
@@ -1,3 +1,3 @@
1
1
  module Wispro
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
data/wispro.gemspec CHANGED
@@ -32,4 +32,7 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_development_dependency 'bundler', '~> 2.0'
34
34
  spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.8'
36
+ spec.add_development_dependency 'rubocop', '~> 0.73'
37
+ spec.add_development_dependency 'webmock', '~> 3.6'
35
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wispro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Gutiérrez del Castillo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-17 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.73'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.73'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
55
97
  description: Wispro Cloud API Client
56
98
  email:
57
99
  - pablogutierrezdelc@gmail.com
@@ -60,6 +102,7 @@ extensions: []
60
102
  extra_rdoc_files: []
61
103
  files:
62
104
  - ".gitignore"
105
+ - ".gitlab-ci.yml"
63
106
  - ".rubocop.yml"
64
107
  - Gemfile
65
108
  - LICENSE.txt