Class: CertificateFactory::Certificate
- Inherits:
-
Object
- Object
- CertificateFactory::Certificate
- Includes:
- HTTParty
- Defined in:
- lib/certificate-factory/certificate.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(url, options = {}) ⇒ Certificate
constructor
A new instance of Certificate.
- #post ⇒ Object
- #result ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Certificate
Returns a new instance of Certificate.
11 12 13 14 15 |
# File 'lib/certificate-factory/certificate.rb', line 11 def initialize(url, = {}) @url = url @dataset_url = [:dataset_url] @campaign = [:campaign] end |
Instance Method Details
#generate ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/certificate-factory/certificate.rb', line 17 def generate response = post if response.code == 202 @dataset_url = response["dataset_url"] { success: "pending", documentation_url: @url, dataset_url: @dataset_url } else { success: "false", published: "false", documentation_url: @url, dataset_url: response["dataset_url"], error: get_error(response) } end end |
#post ⇒ Object
73 74 75 |
# File 'lib/certificate-factory/certificate.rb', line 73 def post self.class.post("/datasets", body: body) end |
#result ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/certificate-factory/certificate.rb', line 53 def result if @dataset_url result = get_result(@dataset_url) { success: result["success"], published: result["published"], documentation_url: @url, certificate_url: result["certificate_url"], user: result["owner_email"] } else response = generate if @dataset_url self.result else response end end end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/certificate-factory/certificate.rb', line 37 def update response = generate if response[:success] != "pending" && response[:error] == "Dataset already exists" dataset_id = response['dataset_id'] response = self.class.post("/datasets/#{dataset_id}/certificates", body: body) { success: response['success'], documentation_url: @url, dataset_url: @dataset_url, error: get_error(response) } else return response end end |