ruby_phpipam 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
  SHA1:
3
- metadata.gz: 03afbcf591d332ec1cb73fb534bff63ad7438162
4
- data.tar.gz: f4cc8ad1794c73ae546b6328db10f5012552d82d
3
+ metadata.gz: 94e627b29e7624df9d6f1a3a72705269be8e0cca
4
+ data.tar.gz: 1b6c9101339c6a0b2dca39a53ecc6525b5c21b61
5
5
  SHA512:
6
- metadata.gz: 2ec050a20f449e859a366d4d854317a8676561c90a2a3691847d285e18b7aa9a326d55ac42784a9d61d0730e5fbdbaac17b1c3ef8e79c473ce781a4b6400e579
7
- data.tar.gz: 4b74f2c12a427ce363e5a162b504b3b64c3a350a092471955693a6d93b6a1bd35fd878d8755bd96ce18105e50e363186927409b930ebd66c8806fa7aa21485c3
6
+ metadata.gz: f0cc58c782851327e7d7c9cbed7eb710c588742d8f8f4874a6ef95c37f09649e76ce5f04b0e7143bac3f54f5070734d1a8ce274ce15392a5bfbf480e03869684
7
+ data.tar.gz: '0867ee83accf8146b7cb6b6c8118a72b17aed9759a26c94b6492b6495b27c9ae38b50935d3e7bb7f16882f69c880cc2aca3f41945ce610da8f8cd406830c5781'
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # ruby_phpipam
2
+ [![Gem Version](https://badge.fury.io/rb/ruby_phpipam.svg)](https://badge.fury.io/rb/ruby_phpipam)
3
+ [![Build Status](https://travis-ci.org/AminArria/ruby-phpipam.svg?branch=master)](https://travis-ci.org/AminArria/ruby-phpipam)
2
4
 
3
5
  **Important Note**: GET actions have highest priority for development, but feel free to make a PR for the others.
4
6
 
@@ -7,7 +9,7 @@
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  ```ruby
10
- gem 'ruby_phpipam', git: 'git://github.com/AminArria/ruby-phpipam'
12
+ gem 'ruby_phpipam'
11
13
 
12
14
  ```
13
15
 
@@ -35,7 +37,8 @@ Phpipam.authenticate
35
37
  ### API Calls
36
38
  In here you'll see the following:
37
39
  ```
38
- method_name() What it does What it returns
40
+ instance_method() What it does What it returns
41
+ self.class_method() What it does What it returns
39
42
  ```
40
43
 
41
44
  #### Section
@@ -62,7 +65,9 @@ all_subnets(mask) Get all posible subnets (CIDR) Array of strings
62
65
 
63
66
  #### Address
64
67
  ```
65
- self.get(id) Get address by ID Address object
68
+ self.get(id) Get address by ID Address object
69
+ self.ping(id) Check status of address Boolean telling if address is reachable
70
+ online? Check status of address Boolean telling if address is reachable
66
71
  ```
67
72
 
68
73
  ## Pending API endpoints
@@ -93,7 +98,6 @@ DELETE /api/my_app/subnets/{id}/permissions/ Removes all permission
93
98
 
94
99
  ### Addresses Endpoints
95
100
  ```
96
- GET /api/my_app/addresses/{id}/ping/ Checks address status
97
101
  GET /api/my_app/addresses/{ip}/{subnetId}/ Returns address from subnet by ip address
98
102
  GET /api/my_app/addresses/search/{ip}/ Searches for addresses in database, returns multiple if found
99
103
  GET /api/my_app/addresses/search_hostname/{hostname}/ Searches for addresses in database by hostname, returns multiple if found
@@ -27,5 +27,19 @@ module RubyPhpipam
27
27
  def self.get(id)
28
28
  Address.new(RubyPhpipam::Query.get("/addresses/#{id}/"))
29
29
  end
30
+
31
+ def self.ping(id)
32
+ response = RubyPhpipam::Query.get("/addresses/#{id}/ping/")
33
+
34
+ if response[:exit_code] == 0
35
+ return true
36
+ else
37
+ return false
38
+ end
39
+ end
40
+
41
+ def online?
42
+ RubyPhpipam::Address.ping(@id)
43
+ end
30
44
  end
31
45
  end
@@ -25,12 +25,23 @@ module RubyPhpipam
25
25
 
26
26
  def validate_token!
27
27
  if @expires <= Time.now
28
- data = RubyPhpipam::Query.get("/user/")
28
+ header = {
29
+ "token" => @token
30
+ }
29
31
 
30
- if data[:expires] <= Time.now
32
+ response = HTTParty.get(RubyPhpipam.gen_url("/user/"), headers: header)
33
+
34
+ body = JSON.parse(response.body, symbolize_names: true)
35
+
36
+ unless body[:success] && body[:code] >= 200 && body[:code] < 400
37
+ raise RequestFailed.new(body[:code], body[:message])
38
+ end
39
+
40
+
41
+ if body[:data][:expires] <= Time.now
31
42
  # Pending re authentication
32
43
  else
33
- @expires = data[:expires]
44
+ @expires = body[:ñdata][:expires]
34
45
  end
35
46
  end
36
47
  end
@@ -9,7 +9,7 @@ module RubyPhpipam
9
9
 
10
10
  body = JSON.parse(response.body, symbolize_names: true)
11
11
 
12
- unless body[:success]
12
+ unless body[:success] && body[:code] >= 200 && body[:code] < 400
13
13
  raise RequestFailed.new(body[:code], body[:message])
14
14
  end
15
15
 
@@ -50,12 +50,16 @@ module RubyPhpipam
50
50
 
51
51
  data = RubyPhpipam::Query.get("/subnets/cidr/#{base}/#{mask}/")
52
52
 
53
- # Currently Rubyphpipam gives the resonse to this query as an array
54
- # just containing the element.
55
- return Subnet.new(data[0])
53
+ if data.nil?
54
+ return nil
55
+ else
56
+ # Currently Rubyphpipam gives the resonse to this query as an array
57
+ # just containing the element.
58
+ return Subnet.new(data[0])
59
+ end
56
60
  end
57
61
 
58
- def usage
62
+ def usage!
59
63
  data = RubyPhpipam::Query.get("/subnets/#{id}/usage/")
60
64
 
61
65
  @used = RubyPhpipam::Helper.to_type(data[:used], :int)
@@ -85,7 +89,7 @@ module RubyPhpipam
85
89
  def first_free_ip
86
90
  # Should this raise an exception if no address available or return nil?
87
91
  # Currently it returns nil
88
- data = RubyPhpipam::Query.get("/subnets/#{id}/first_free/")
92
+ RubyPhpipam::Query.get("/subnets/#{id}/first_free/")
89
93
  end
90
94
 
91
95
  def slaves
@@ -104,12 +108,13 @@ module RubyPhpipam
104
108
  end
105
109
  end
106
110
 
107
- def first_subnet(mask)
108
- RubyPhpipam::Query.get("/subnets/#{id}/first_subnet/#{mask}/")
111
+ def first_subnet(slave_mask)
112
+ # nil when no available subnet exists
113
+ RubyPhpipam::Query.get("/subnets/#{id}/first_subnet/#{slave_mask}/")
109
114
  end
110
115
 
111
- def all_subnets(mask)
112
- RubyPhpipam::Query.get_array("/subnets/#{id}/all_subnets/#{mask}/")
116
+ def all_subnets(slave_mask)
117
+ RubyPhpipam::Query.get_array("/subnets/#{id}/all_subnets/#{slave_mask}/")
113
118
  end
114
119
  end
115
120
  end
@@ -1,3 +1,3 @@
1
1
  module RubyPhpipam
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["arria.amin@gmail.com"]
11
11
 
12
12
  spec.summary = "Ruby wrapper for the phpipam API"
13
- spec.description = "Ruby client for the phpipam API"
13
+ spec.description = "Ruby wrapper for the phpipam API"
14
14
  spec.homepage = "https://github.com/AminArria/ruby-phpipam"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_phpipam
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
  - Amin Arria
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: Ruby client for the phpipam API
111
+ description: Ruby wrapper for the phpipam API
112
112
  email:
113
113
  - arria.amin@gmail.com
114
114
  executables: []