playpath_rails 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbed443abfa5659dc3d9594b12415c057065e618fe4d84850485b1c4441f585e
4
- data.tar.gz: 40a8f4e3c9f88cc046c96867bdbf072f70d50f153bcf821ef4e1b85ac9e49ec2
3
+ metadata.gz: 2e5ab5d5c4afc526c183ae6436a55e7560f3af87c5f7d5a478d6608c6346625d
4
+ data.tar.gz: c1fcd5c787be950c3cd9379cdca59b7cb6313a6fe6a2faae177157123dca4205
5
5
  SHA512:
6
- metadata.gz: ccea8d24e6032d8e6ccf1dafa9f342e9b21b6ecc9f2cd419976f7d9c40edd6b77e4e434413260a6aaca8d24246e89f8d28ef969ffd6782682f85a3886349169c
7
- data.tar.gz: 386ca5d6222d3d23bdfdd124af4fe0ecc2516a45f13a64aea942d909f71d7c5230e4480fc337cbac8652076a5b3d286a8a5f135fcc3e7912a25a87f3c94dd369
6
+ metadata.gz: fc1c36c9224140d045df0c54b6d798dc4f3776888126c3b107669d7ce5bdea2effa68e4bff815e22d592c2e9fa29757ba9afe02714ade055eca1e5c294a60b60
7
+ data.tar.gz: 166c3ddc43552c6c89f57934f3f4fccd3f857877ac4603cfa877cac8f71d285f4257e903ba0d3baa5c6c4d07973468f895476a84937485558e43aacf998642b8
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -11,31 +11,30 @@ PlaypathRails.configure do |config|
11
11
  config.base_url = 'https://playpath.io'
12
12
  end
13
13
 
14
- puts "PlaypathRails Example Usage"
15
- puts "=" * 40
14
+ puts 'PlaypathRails Example Usage'
15
+ puts '=' * 40
16
16
 
17
17
  # Example 1: Direct API usage
18
18
  puts "\n1. Direct API Usage:"
19
19
  begin
20
20
  client = PlaypathRails.client
21
-
21
+
22
22
  # Create an item
23
- puts "Creating an item..."
23
+ puts 'Creating an item...'
24
24
  item = client.create_item(
25
- title: "Ruby Programming Basics",
26
- url: "https://example.com/ruby-basics",
27
- text: "Learn the fundamentals of Ruby programming language",
28
- tags: ["ruby", "programming", "tutorial"]
25
+ title: 'Ruby Programming Basics',
26
+ url: 'https://example.com/ruby-basics',
27
+ text: 'Learn the fundamentals of Ruby programming language',
28
+ tags: %w[ruby programming tutorial]
29
29
  )
30
30
  puts "Created item: #{item['title']} (ID: #{item['id']})"
31
-
31
+
32
32
  # List items
33
33
  puts "\nListing items..."
34
34
  items = client.list_items
35
35
  puts "Found #{items.length} items"
36
-
37
36
  rescue PlaypathRails::AuthenticationError
38
- puts "Error: Please configure a valid API key"
37
+ puts 'Error: Please configure a valid API key'
39
38
  rescue PlaypathRails::APIError => e
40
39
  puts "API Error: #{e.message}"
41
40
  end
@@ -44,40 +43,39 @@ end
44
43
  puts "\n2. RAG Chat Usage:"
45
44
  begin
46
45
  # Simple question
47
- puts "Asking a simple question..."
48
- response = PlaypathRails::RAG.ask("What is Ruby programming?")
46
+ puts 'Asking a simple question...'
47
+ response = PlaypathRails::RAG.ask('What is Ruby programming?')
49
48
  puts "Response: #{response}"
50
-
49
+
51
50
  # Chat with history
52
51
  puts "\nChat with conversation history..."
53
52
  history = PlaypathRails::RAG.build_history(
54
- "What is Ruby?",
55
- "Ruby is a dynamic programming language...",
56
- "What are its main features?"
53
+ 'What is Ruby?',
54
+ 'Ruby is a dynamic programming language...',
55
+ 'What are its main features?'
57
56
  )
58
-
57
+
59
58
  result = PlaypathRails::RAG.chat(
60
- message: "Can you give me some examples?",
59
+ message: 'Can you give me some examples?',
61
60
  history: history
62
61
  )
63
62
  puts "Response: #{result['reply']}"
64
63
  puts "Usage: #{result['usage']}/#{result['limit']}" if result['usage']
65
-
66
64
  rescue PlaypathRails::AuthenticationError
67
- puts "Error: Please configure a valid API key"
65
+ puts 'Error: Please configure a valid API key'
68
66
  rescue PlaypathRails::TrialLimitError
69
- puts "Error: Trial limit exceeded"
67
+ puts 'Error: Trial limit exceeded'
70
68
  rescue PlaypathRails::APIError => e
71
69
  puts "API Error: #{e.message}"
72
70
  end
73
71
 
74
72
  # Example 3: Model synchronization (simulated)
75
73
  puts "\n3. Model Synchronization Example:"
76
- puts "In a Rails application, you would include the Synchronizable module:"
74
+ puts 'In a Rails application, you would include the Synchronizable module:'
77
75
  puts <<~RUBY
78
76
  class Article < ApplicationRecord
79
77
  include PlaypathRails::Synchronizable
80
-
78
+ #{' '}
81
79
  # Configure synchronization
82
80
  playpath_sync(
83
81
  title_field: :title,
@@ -87,7 +85,7 @@ puts <<~RUBY
87
85
  tags: ['article', 'blog']
88
86
  )
89
87
  end
90
-
88
+
91
89
  # Then create/update records normally:
92
90
  article = Article.create!(
93
91
  title: "My Blog Post",
@@ -95,10 +93,10 @@ puts <<~RUBY
95
93
  permalink: "https://myblog.com/my-post",
96
94
  tag_list: ["ruby", "rails"]
97
95
  )
98
-
96
+
99
97
  # The record will be automatically synced to PlayPath.io
100
98
  # You can also manually sync:
101
99
  article.sync_to_playpath!
102
100
  RUBY
103
101
 
104
- puts "\nExample completed!"
102
+ puts "\nExample completed!"
@@ -86,16 +86,14 @@ module PlaypathRails
86
86
 
87
87
  request = request_class.new(uri)
88
88
  request['Content-Type'] = 'application/json'
89
-
89
+
90
90
  # Set authentication header
91
91
  api_key = configuration.api_key_for(endpoint_type)
92
92
  raise AuthenticationError, 'API key not configured' unless api_key
93
-
93
+
94
94
  request['X-Api-Key'] = api_key
95
95
 
96
- if body
97
- request.body = JSON.generate(body)
98
- end
96
+ request.body = JSON.generate(body) if body
99
97
 
100
98
  request
101
99
  end
@@ -104,6 +102,7 @@ module PlaypathRails
104
102
  case response.code.to_i
105
103
  when 200, 201
106
104
  return nil if response.body.nil? || response.body.empty?
105
+
107
106
  JSON.parse(response.body)
108
107
  when 204
109
108
  nil
@@ -116,9 +115,10 @@ module PlaypathRails
116
115
  error_data = parse_error_response(response)
117
116
  if error_data[:message]&.include?('Trial limit')
118
117
  raise TrialLimitError.new(error_data[:message], status_code: 403, response_body: response.body)
119
- else
120
- raise APIError.new('Forbidden', status_code: 403, response_body: response.body)
121
118
  end
119
+
120
+ raise APIError.new('Forbidden', status_code: 403, response_body: response.body)
121
+
122
122
  when 404
123
123
  raise NotFoundError.new('Resource not found', status_code: 404, response_body: response.body)
124
124
  when 422
@@ -129,18 +129,20 @@ module PlaypathRails
129
129
  raise RateLimitError.new('Rate limit exceeded', status_code: 429, response_body: response.body)
130
130
  when 502
131
131
  error_data = parse_error_response(response)
132
- raise ExternalServiceError.new(error_data[:message] || 'Bad Gateway', status_code: 502, response_body: response.body)
132
+ raise ExternalServiceError.new(error_data[:message] || 'Bad Gateway', status_code: 502,
133
+ response_body: response.body)
133
134
  else
134
- raise APIError.new("HTTP #{response.code}: #{response.message}", status_code: response.code.to_i, response_body: response.body)
135
+ raise APIError.new("HTTP #{response.code}: #{response.message}", status_code: response.code.to_i,
136
+ response_body: response.body)
135
137
  end
136
138
  end
137
139
 
138
140
  def parse_error_response(response)
139
141
  return { message: 'Unknown error' } if response.body.nil? || response.body.empty?
140
-
142
+
141
143
  JSON.parse(response.body, symbolize_names: true)
142
144
  rescue JSON::ParserError
143
145
  { message: response.body }
144
146
  end
145
147
  end
146
- end
148
+ end
@@ -32,4 +32,4 @@ module PlaypathRails
32
32
 
33
33
  # External service error (e.g., OpenAI API)
34
34
  class ExternalServiceError < APIError; end
35
- end
35
+ end
@@ -9,12 +9,12 @@ module PlaypathRails
9
9
  include ActiveRecord::Generators::Migration
10
10
 
11
11
  source_root File.expand_path('templates', __dir__)
12
-
13
- argument :model_name, type: :string, desc: "The model to add PlayPath synchronization to"
12
+
13
+ argument :model_name, type: :string, desc: 'The model to add PlayPath synchronization to'
14
14
 
15
15
  def create_migration_file
16
- migration_template 'add_playpath_item_id_migration.rb.erb',
17
- "db/migrate/add_playpath_item_id_to_#{table_name}.rb"
16
+ migration_template 'add_playpath_item_id_migration.rb.erb',
17
+ "db/migrate/add_playpath_item_id_to_#{table_name}.rb"
18
18
  end
19
19
 
20
20
  private
@@ -28,4 +28,4 @@ module PlaypathRails
28
28
  end
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -33,4 +33,4 @@ module PlaypathRails
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -9,12 +9,8 @@ module PlaypathRails
9
9
 
10
10
  included do
11
11
  # Only add callbacks if the host class supports them
12
- if respond_to?(:after_commit)
13
- after_commit :playpath_sync!, on: [:create, :update]
14
- end
15
- if respond_to?(:before_destroy)
16
- before_destroy :playpath_delete!
17
- end
12
+ after_commit :playpath_sync!, on: %i[create update] if respond_to?(:after_commit)
13
+ before_destroy :playpath_delete! if respond_to?(:before_destroy)
18
14
  end
19
15
 
20
16
  class_methods do
@@ -49,7 +45,7 @@ module PlaypathRails
49
45
 
50
46
  begin
51
47
  item_data = build_item_data
52
-
48
+
53
49
  if playpath_item_id && playpath_item_id != 0
54
50
  # Update existing item
55
51
  PlaypathRails.client.update_item(playpath_item_id, **item_data)
@@ -57,11 +53,9 @@ module PlaypathRails
57
53
  # Create new item
58
54
  response = PlaypathRails.client.create_item(**item_data)
59
55
  # Store the item ID if the model supports it
60
- if respond_to?(:playpath_item_id=) && response&.dig('id')
61
- update_column(:playpath_item_id, response['id'])
62
- end
56
+ update_column(:playpath_item_id, response['id']) if respond_to?(:playpath_item_id=) && response&.dig('id')
63
57
  end
64
-
58
+
65
59
  true
66
60
  rescue PlaypathRails::Error => e
67
61
  # Log the error but don't raise it to avoid breaking the application
@@ -95,6 +89,7 @@ module PlaypathRails
95
89
  # Get the PlayPath item ID for this record
96
90
  def playpath_item_id
97
91
  return nil unless respond_to?(:playpath_item_id)
92
+
98
93
  read_attribute(:playpath_item_id)
99
94
  end
100
95
 
@@ -111,9 +106,7 @@ module PlaypathRails
111
106
  return false unless title_value && !title_value.to_s.empty?
112
107
 
113
108
  # If 'only' fields are specified, check if any of them changed
114
- if options[:only] && options[:only].any?
115
- return options[:only].any? { |field| saved_change_to_attribute?(field) }
116
- end
109
+ return options[:only].any? { |field| saved_change_to_attribute?(field) } if options[:only]&.any?
117
110
 
118
111
  true
119
112
  end
@@ -140,10 +133,10 @@ module PlaypathRails
140
133
 
141
134
  # Tags handling
142
135
  tags = []
143
-
136
+
144
137
  # Add static tags
145
- tags.concat(options[:tags]) if options[:tags] && options[:tags].any?
146
-
138
+ tags.concat(options[:tags]) if options[:tags]&.any?
139
+
147
140
  # Add dynamic tags from field
148
141
  if options[:tags_field] && respond_to?(options[:tags_field])
149
142
  field_tags = send(options[:tags_field])
@@ -161,4 +154,4 @@ module PlaypathRails
161
154
  data
162
155
  end
163
156
  end
164
- end
157
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlaypathRails
4
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
5
5
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "playpath_rails/version"
4
- require_relative "playpath_rails/errors"
5
- require_relative "playpath_rails/client"
6
- require_relative "playpath_rails/synchronizable"
7
- require_relative "playpath_rails/rag"
3
+ require_relative 'playpath_rails/version'
4
+ require_relative 'playpath_rails/errors'
5
+ require_relative 'playpath_rails/client'
6
+ require_relative 'playpath_rails/synchronizable'
7
+ require_relative 'playpath_rails/rag'
8
+ require_relative 'playpath_rails/railtie' if defined?(Rails)
8
9
 
9
10
  module PlaypathRails
10
11
  class Error < StandardError; end
@@ -43,7 +44,7 @@ module PlaypathRails
43
44
  def initialize
44
45
  @api_key = nil
45
46
  @embeddings_api_key = nil
46
- @base_url = "https://playpath.io"
47
+ @base_url = 'https://playpath.io'
47
48
  end
48
49
 
49
50
  # Get the appropriate API key for the request type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playpath_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joran Kikke
@@ -121,33 +121,33 @@ dependencies:
121
121
  - !ruby/object:Gem::Version
122
122
  version: '2.0'
123
123
  - !ruby/object:Gem::Dependency
124
- name: webmock
124
+ name: simplecov
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '3.0'
129
+ version: '0.22'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '3.0'
136
+ version: '0.22'
137
137
  - !ruby/object:Gem::Dependency
138
- name: simplecov
138
+ name: webmock
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '0.22'
143
+ version: '3.0'
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '0.22'
150
+ version: '3.0'
151
151
  description: |-
152
152
  Provides integration between ActiveRecord and the Items API at playpath.io,
153
153
  enabling automatic synchronization of records between your Rails application
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
191
  - - ">="
192
192
  - !ruby/object:Gem::Version
193
- version: 3.1.0
193
+ version: 2.6.0
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements:
196
196
  - - ">="