Class: Traceparts::Client
- Inherits:
-
Object
- Object
- Traceparts::Client
- Defined in:
- lib/traceparts/client.rb
Constant Summary collapse
- API_BASE =
'http://ws.tracepartsonline.net'- WEB_SERVICE_PATH =
'/tpowebservices'
Instance Method Summary collapse
- #available_formats(classification_id, part_number, user_email) ⇒ Object
- #catalogs ⇒ Object
- #categories(classification_id) ⇒ Object
- #download_archive_link(classification_id, part_number, cad_format_id, user_email) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
-
#page_products(classification_id, category_path = nil, page = 1) ⇒ Object
Returns product family id’s for specified page.
- #part(classification_id, part_number, user_email) ⇒ Object
- #part_details(classification_id, part_number, user_email) ⇒ Object
-
#products(catalog_id, category_path = nil) ⇒ Object
Returns all product family id’s available.
- #register_user(user_email, company, country, first_name, last_name, phone) ⇒ Object
- #user(user_email) ⇒ Object
- #user_exists?(user_email) ⇒ Boolean
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 |
# File 'lib/traceparts/client.rb', line 16 def initialize(api_key) @api_key = api_key @connection = Faraday.new(url: API_BASE) do |faraday| faraday.adapter(Faraday.default_adapter) end end |
Instance Method Details
#available_formats(classification_id, part_number, user_email) ⇒ Object
59 60 61 62 63 |
# File 'lib/traceparts/client.rb', line 59 def available_formats(classification_id, part_number, user_email) json = json_available_formats(classification_id, part_number, user_email) json.map { |format| CadFormat.new(self, format) } end |
#catalogs ⇒ Object
24 25 26 |
# File 'lib/traceparts/client.rb', line 24 def catalogs json_catalogs['classificationList'].map { |catalog| Catalog.new(self, catalog) } end |
#categories(classification_id) ⇒ Object
28 29 30 |
# File 'lib/traceparts/client.rb', line 28 def categories(classification_id) json_categories(classification_id)['categorieList'].map { |category| Category.new(self, category) } end |
#download_archive_link(classification_id, part_number, cad_format_id, user_email) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/traceparts/client.rb', line 65 def download_archive_link(classification_id, part_number, cad_format_id, user_email) response = get_request('DownloadCADPath', { 'PartNumber' => part_number, 'ClassificationID' => classification_id, 'CADFormatID' => cad_format_id, 'UserEmail' => user_email }) json = JSON.parse(response.body) json[1][0][1] end |
#page_products(classification_id, category_path = nil, page = 1) ⇒ Object
Returns product family id’s for specified page
33 34 35 36 37 |
# File 'lib/traceparts/client.rb', line 33 def page_products(classification_id, category_path = nil, page = 1) json = json_products(classification_id, category_path, page) products_present?(json) ? bind_products(json) : [] end |
#part(classification_id, part_number, user_email) ⇒ Object
78 79 80 |
# File 'lib/traceparts/client.rb', line 78 def part(classification_id, part_number, user_email) Part.new(self, classification_id, part_number, user_email) end |
#part_details(classification_id, part_number, user_email) ⇒ Object
53 54 55 56 57 |
# File 'lib/traceparts/client.rb', line 53 def part_details(classification_id, part_number, user_email) json = json_part_details(classification_id, part_number, user_email) PartDetails.new(json) end |
#products(catalog_id, category_path = nil) ⇒ Object
Returns all product family id’s available
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/traceparts/client.rb', line 40 def products(catalog_id, category_path = nil) page = 1 all_products = [] while (products_for_page = page_products(catalog_id, category_path, page)).any? do all_products.push(*products_for_page) page += 1 end all_products end |
#register_user(user_email, company, country, first_name, last_name, phone) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/traceparts/client.rb', line 96 def register_user(user_email, company, country, first_name, last_name, phone) response = get_request('UserRegistration', { 'UserEmail' => user_email, 'company' => company, 'country' => country, 'fname' => first_name, 'name' => last_name, 'phone' => phone }) json = JSON.parse(response.body) json['registered'] == true end |
#user(user_email) ⇒ Object
82 83 84 |
# File 'lib/traceparts/client.rb', line 82 def user(user_email) User.new(self, user_email) end |
#user_exists?(user_email) ⇒ Boolean
86 87 88 89 90 91 92 93 94 |
# File 'lib/traceparts/client.rb', line 86 def user_exists?(user_email) response = get_request('CheckLogin', { 'UserEmail' => user_email }) json = JSON.parse(response.body) json['registered'] == true end |