Class: Fp::Client
- Inherits:
-
Object
- Object
- Fp::Client
- Defined in:
- lib/fp/client.rb
Overview
HTTP client for the FeatureParity API
Instance Method Summary collapse
-
#create_requirement(params) ⇒ Object
POST /requirements.
-
#find_requirement_by_slug(workspace_id, slug) ⇒ Object
GET /requirements by slug within a workspace.
-
#get_gaps(workspace_id, surface: nil) ⇒ Object
GET /gaps (when API is ready).
-
#get_matrix(workspace_id, format: :json) ⇒ Object
GET /matrix (when API is ready).
-
#get_project(id) ⇒ Object
GET /workspaces/:id.
-
#get_requirement(id) ⇒ Object
GET /requirements/:id.
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
-
#list_projects ⇒ Object
GET /workspaces (called "projects" in the CLI).
-
#list_requirements(workspace_id: nil, status: nil) ⇒ Object
GET /requirements.
-
#report_evidence(params) ⇒ Object
POST /evidence (when API is ready).
-
#update_requirement(id, params) ⇒ Object
PUT /requirements/:id.
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/fp/client.rb', line 10 def initialize(config) @config = config @base_url = config.api_url.chomp('/') end |
Instance Method Details
#create_requirement(params) ⇒ Object
POST /requirements
55 56 57 |
# File 'lib/fp/client.rb', line 55 def create_requirement(params) post('/api/requirements', params) end |
#find_requirement_by_slug(workspace_id, slug) ⇒ Object
GET /requirements by slug within a workspace
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fp/client.rb', line 39 def find_requirement_by_slug(workspace_id, slug) # List all requirements for the workspace and find by slug result = list_requirements(workspace_id: workspace_id) return result unless result[:ok] requirements = result[:data]['requirements'] || [] requirement = requirements.find { |r| r['slug'] == slug } if requirement { ok: true, data: { 'requirement' => requirement } } else { ok: false, error: "Requirement '#{slug}' not found in workspace", status: 404 } end end |
#get_gaps(workspace_id, surface: nil) ⇒ Object
GET /gaps (when API is ready)
76 77 78 79 80 |
# File 'lib/fp/client.rb', line 76 def get_gaps(workspace_id, surface: nil) params = { workspace_id: workspace_id } params[:surface] = surface if surface get('/api/gaps', params) end |
#get_matrix(workspace_id, format: :json) ⇒ Object
GET /matrix (when API is ready)
70 71 72 73 |
# File 'lib/fp/client.rb', line 70 def get_matrix(workspace_id, format: :json) path = format == :csv ? '/api/matrix.csv' : '/api/matrix' get(path, { workspace_id: workspace_id }) end |
#get_project(id) ⇒ Object
GET /workspaces/:id
21 22 23 |
# File 'lib/fp/client.rb', line 21 def get_project(id) get("/api/workspaces/#{id}") end |
#get_requirement(id) ⇒ Object
GET /requirements/:id
34 35 36 |
# File 'lib/fp/client.rb', line 34 def get_requirement(id) get("/api/requirements/#{id}") end |
#list_projects ⇒ Object
GET /workspaces (called "projects" in the CLI)
16 17 18 |
# File 'lib/fp/client.rb', line 16 def list_projects get('/api/workspaces') end |
#list_requirements(workspace_id: nil, status: nil) ⇒ Object
GET /requirements
26 27 28 29 30 31 |
# File 'lib/fp/client.rb', line 26 def list_requirements(workspace_id: nil, status: nil) params = {} params[:workspace_id] = workspace_id if workspace_id params[:status] = status if status get('/api/requirements', params) end |
#report_evidence(params) ⇒ Object
POST /evidence (when API is ready)
65 66 67 |
# File 'lib/fp/client.rb', line 65 def report_evidence(params) post('/api/evidence', params) end |
#update_requirement(id, params) ⇒ Object
PUT /requirements/:id
60 61 62 |
# File 'lib/fp/client.rb', line 60 def update_requirement(id, params) put("/api/requirements/#{id}", params) end |