Class: Opdb::Client
- Inherits:
-
Object
- Object
- Opdb::Client
- Includes:
- ApiExceptions, HttpStatusCodes
- Defined in:
- lib/opdb/client.rb
Overview
Client wrapping the Open Pinball Database API
Constant Summary collapse
- API_BASE_URI =
"https://opdb.org/api"
Constants included from HttpStatusCodes
HttpStatusCodes::HTTP_BAD_REQUEST_CODE, HttpStatusCodes::HTTP_FORBIDDEN_CODE, HttpStatusCodes::HTTP_NOT_FOUND_CODE, HttpStatusCodes::HTTP_OK_CODE, HttpStatusCodes::HTTP_UNAUTHORIZED_CODE, HttpStatusCodes::HTTP_UNPROCESSABLE_ENTITY_CODE
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
Instance Method Summary collapse
-
#changelog ⇒ Object
Public Requests.
- #export_machine_groups ⇒ Object
- #export_machines ⇒ Object
- #get_machine_info(opdb_id:) ⇒ Object
- #get_machine_info_by_ipdb_id(ipdb_id:) ⇒ Object
-
#initialize(api_token: nil) ⇒ Client
constructor
A new instance of Client.
-
#search_machines(q:, require_opdb: "1", include_groups: "0", include_aliases: "1", include_grouping_entries: "0") ⇒ Object
Requests that require a valid api_token.
-
#typeahead_search(q:, include_groups: "0", include_aliases: "1") ⇒ Object
rubocop:disable Naming/MethodParameterName.
Constructor Details
#initialize(api_token: nil) ⇒ Client
Returns a new instance of Client.
18 19 20 |
# File 'lib/opdb/client.rb', line 18 def initialize(api_token: nil) @api_token = api_token end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
16 17 18 |
# File 'lib/opdb/client.rb', line 16 def api_token @api_token end |
Instance Method Details
#changelog ⇒ Object
Public Requests
23 24 25 26 27 28 |
# File 'lib/opdb/client.rb', line 23 def changelog request( http_method: :get, endpoint: "changelog" ) end |
#export_machine_groups ⇒ Object
78 79 80 81 82 83 |
# File 'lib/opdb/client.rb', line 78 def export_machine_groups private_request( http_method: :get, endpoint: "export/groups" ) end |
#export_machines ⇒ Object
71 72 73 74 75 76 |
# File 'lib/opdb/client.rb', line 71 def export_machines private_request( http_method: :get, endpoint: "export" ) end |
#get_machine_info(opdb_id:) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/opdb/client.rb', line 57 def get_machine_info(opdb_id:) private_request( http_method: :get, endpoint: "machines/#{opdb_id}" ) end |
#get_machine_info_by_ipdb_id(ipdb_id:) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/opdb/client.rb', line 64 def get_machine_info_by_ipdb_id(ipdb_id:) private_request( http_method: :get, endpoint: "machines/ipdb/#{ipdb_id}" ) end |
#search_machines(q:, require_opdb: "1", include_groups: "0", include_aliases: "1", include_grouping_entries: "0") ⇒ Object
Requests that require a valid api_token
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opdb/client.rb', line 43 def search_machines(q:, require_opdb: "1", include_groups: "0", include_aliases: "1", include_grouping_entries: "0") # rubocop:disable Naming/MethodParameterName, Metrics/MethodLength private_request( http_method: :get, endpoint: "search", params: { q: q, require_opdb: require_opdb, include_groups: include_groups, include_aliases: include_aliases, include_grouping_entries: include_grouping_entries } ) end |
#typeahead_search(q:, include_groups: "0", include_aliases: "1") ⇒ Object
rubocop:disable Naming/MethodParameterName
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/opdb/client.rb', line 30 def typeahead_search(q:, include_groups: "0", include_aliases: "1") # rubocop:disable Naming/MethodParameterName request( http_method: :get, endpoint: "search/typeahead", params: { q: q, include_groups: include_groups, include_aliases: include_aliases } ) end |