api_version.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module ShopifyAPI
  2. class ApiVersion
  3. class NoVersion < ApiVersion
  4. API_PREFIX = '/admin/'
  5. GRAPHQL_PATH = '/admin/api/graphql.json'
  6. def initialize
  7. @version_name = "no version"
  8. end
  9. def construct_api_path(path)
  10. "#{API_PREFIX}#{path}"
  11. end
  12. def construct_graphql_path
  13. GRAPHQL_PATH
  14. end
  15. end
  16. class Unstable < ApiVersion
  17. API_PREFIX = '/admin/api/unstable/'
  18. def initialize
  19. @version_name = "unstable"
  20. end
  21. def construct_api_path(path)
  22. "#{API_PREFIX}#{path}"
  23. end
  24. def construct_graphql_path
  25. construct_api_path('graphql.json')
  26. end
  27. end
  28. def self.no_version
  29. NoVersion.new
  30. end
  31. def self.unstable
  32. Unstable.new
  33. end
  34. def to_s
  35. @version_name
  36. end
  37. def inspect
  38. @version_name
  39. end
  40. def ==(other)
  41. other.class == self.class && to_s == other.to_s
  42. end
  43. def hash
  44. version_name.hash
  45. end
  46. def construct_api_path(_path)
  47. raise NotImplementedError
  48. end
  49. def construct_graphql_path
  50. raise NotImplementedError
  51. end
  52. end
  53. end