shopify_app_lrb3 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/CHANGELOG +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +19 -0
  6. data/README.md +182 -0
  7. data/RELEASING +16 -0
  8. data/Rakefile +11 -0
  9. data/install.rb +25 -0
  10. data/lib/generators/shopify_app/README +23 -0
  11. data/lib/generators/shopify_app/USAGE +22 -0
  12. data/lib/generators/shopify_app/shopify_app_generator.rb +69 -0
  13. data/lib/generators/shopify_app/templates/app/assets/images/favicon.png +0 -0
  14. data/lib/generators/shopify_app/templates/app/assets/images/grid-18px.png +0 -0
  15. data/lib/generators/shopify_app/templates/app/assets/images/shopify-114.png +0 -0
  16. data/lib/generators/shopify_app/templates/app/assets/images/shopify-57.png +0 -0
  17. data/lib/generators/shopify_app/templates/app/assets/images/shopify-72.png +0 -0
  18. data/lib/generators/shopify_app/templates/app/assets/images/shopify.png +0 -0
  19. data/lib/generators/shopify_app/templates/app/assets/javascripts/application.js +15 -0
  20. data/lib/generators/shopify_app/templates/app/assets/stylesheets/application.css +10 -0
  21. data/lib/generators/shopify_app/templates/app/assets/stylesheets/imports.css.less +5 -0
  22. data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app.css.scss +150 -0
  23. data/lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app_buttons.css.less +77 -0
  24. data/lib/generators/shopify_app/templates/app/controllers/application_controller.rb +13 -0
  25. data/lib/generators/shopify_app/templates/app/controllers/home_controller.rb +18 -0
  26. data/lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb +52 -0
  27. data/lib/generators/shopify_app/templates/app/helpers/home_helper.rb +9 -0
  28. data/lib/generators/shopify_app/templates/app/helpers/login_helper.rb +3 -0
  29. data/lib/generators/shopify_app/templates/app/helpers/tabs_helper.rb +11 -0
  30. data/lib/generators/shopify_app/templates/app/views/home/design.html.erb +3542 -0
  31. data/lib/generators/shopify_app/templates/app/views/home/index.html.erb +168 -0
  32. data/lib/generators/shopify_app/templates/app/views/home/welcome.html.erb +110 -0
  33. data/lib/generators/shopify_app/templates/app/views/layouts/application.html.erb +79 -0
  34. data/lib/generators/shopify_app/templates/app/views/sessions/new.html.erb +21 -0
  35. data/lib/generators/shopify_app/templates/config/initializers/omniauth.rb +14 -0
  36. data/lib/generators/shopify_app/templates/config/initializers/shopify_session_repository.rb +21 -0
  37. data/lib/generators/shopify_app/templates/public/404.html +40 -0
  38. data/lib/generators/shopify_app/templates/public/422.html +40 -0
  39. data/lib/generators/shopify_app/templates/public/500.html +40 -0
  40. data/lib/generators/shopify_app/templates/public/favicon.png +0 -0
  41. data/lib/generators/shopify_app/templates/public/shopify-114.png +0 -0
  42. data/lib/generators/shopify_app/templates/public/shopify-57.png +0 -0
  43. data/lib/generators/shopify_app/templates/public/shopify-72.png +0 -0
  44. data/lib/shopify_app.rb +20 -0
  45. data/lib/shopify_app/configuration.rb +46 -0
  46. data/lib/shopify_app/in_memory_session_store.rb +25 -0
  47. data/lib/shopify_app/login_protection.rb +39 -0
  48. data/lib/shopify_app/railtie.rb +17 -0
  49. data/lib/shopify_app/shopify_session_repository.rb +22 -0
  50. data/lib/shopify_app/version.rb +3 -0
  51. data/shipit.rubygems.yml +1 -0
  52. data/shopify_app.gemspec +30 -0
  53. data/test/config/development_config_file.yml +7 -0
  54. data/test/config/empty_config_file.yml +1 -0
  55. data/test/config/other_config_file.yml +3 -0
  56. data/test/config/shopify_app.yml +3 -0
  57. data/test/lib/shopify_app/configuration_test.rb +78 -0
  58. data/test/lib/shopify_app/in_memory_session_store_test.rb +35 -0
  59. data/test/lib/shopify_app/shopify_session_repository_test.rb +57 -0
  60. data/test/test_helper.rb +5 -0
  61. metadata +214 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c161a8e46435589a6f6ce0bb35cd0531019b06e
4
+ data.tar.gz: fe0f9dcb3ddf9b8ccc61b79fbb7a43faf6a66b56
5
+ SHA512:
6
+ metadata.gz: c2d8958764f430c420a0f748c090107dbcaabaa616aac82e3ac757f9ff42c6535d20bd4cb001fba680e2e7dd4c18229aeb61d7cc175a020ab4a837711c67454c
7
+ data.tar.gz: adba2d4c05acb67fea15431b99e1700d61f82e392b9533c7d6a15a0c2a3ba2267f4d4f8e2a96451733513784befaf50db9993165b05f24e083c22238a0e44b95
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ .yardoc
7
+ doc/
@@ -0,0 +1,5 @@
1
+ * re-styled with Twitter Bootstrap css framework and updated docs [warren]
2
+ * Require shopify_api gem via proper railtie setup [willem]
3
+ * Don't require shopify.yml when using environment variables [cody]
4
+ * Renamed instances of current_shop to shop_session to maintain logic
5
+ * Replace old LoginController with a RESTful SessionsController
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in shopify_app.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Shopify
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,182 @@
1
+ # Shopify App
2
+
3
+ [![Build Status](https://travis-ci.org/Shopify/shopify_app.png)](https://travis-ci.org/Shopify/shopify_app)
4
+
5
+ Shopify application generator for Rails 3.1 and Rails 4.0
6
+
7
+ ## Description
8
+
9
+ This gem makes it easy to get a Rails 3.1 or Rails 4.0 app up and running with the Shopify API.
10
+
11
+ The generator creates a basic SessionsController for authenticating with your shop and a HomeController which displays basic information about your products, orders and articles.
12
+
13
+ *Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete some of your files.*
14
+
15
+ ## Installation
16
+
17
+ ``` sh
18
+ # Create a new rails app
19
+ $ rails new my_shopify_app
20
+ $ cd my_shopify_app
21
+
22
+ # Add the gem shopify_app to your Gemfile
23
+ $ echo "gem 'shopify_app'" >> Gemfile
24
+ $ bundle install
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ``` sh
30
+ $ rails generate shopify_app your_app_api_key your_app_secret
31
+ ```
32
+
33
+ If you don't have an API key yet, create a Shopify Partner account at http://shopify.com/partners and create an app. You can also create test shops once you're logged in as a partner.
34
+
35
+ When you create your app in the Shopify Partner Account, set the Application Callback URL to
36
+
37
+ http://localhost:3000
38
+
39
+ You can also create a private application that only works for your shop by visiting https://YOUR-SHOP.myshopify.com/admin/apps/private.
40
+
41
+ ### Example
42
+
43
+ ``` sh
44
+ $ rails generate shopify_app edffbb1bb793e2750686e6f4647a384a fed5bb18hde3e2750686e6f4647a781a
45
+ ```
46
+
47
+ This will create a LoginController and a HomeController with their own views.
48
+
49
+ ## Configuring Shopify App
50
+
51
+ It's possible to set your API key and secret key from different sources:
52
+
53
+ * `SHOPIFY_APP_API_KEY` and `SHOPIFY_APP_SECRET` environment variables
54
+ * Configuration in a Rails `<environment>.rb` config file
55
+
56
+ ``` ruby
57
+ config.shopify.api_key = 'your api key'
58
+ config.shopify.secret = 'your secret'
59
+ ```
60
+
61
+ * Configuration loaded from `<environment>` key in `shopify_app.yml`
62
+
63
+ ``` yaml
64
+ development:
65
+ api_key: your api key
66
+ secret: your secret
67
+ ```
68
+
69
+ * Configuration loaded from common key in `shopify_app.yml`
70
+
71
+ ``` yaml
72
+ common:
73
+ api_key: your api key
74
+ secret: your secret
75
+ ```
76
+
77
+ ## Set up your ShopifySessionRepository.store
78
+
79
+ `ShopifySessionRepository` allows you as a developer to define how your sessions are retrieved and
80
+ stored for a shop. This can simply be your `Shop` model that stores the API Token and shop name. If
81
+ you are using ActiveRecord, then all you need to implement is `self.store(shopify_session)` and
82
+ `self.retrieve(id)` in order to store the record on disk or retrieve it for use at a later point.
83
+ It is imperative that your store method returns the identifier for the session. Typically this is
84
+ just the record ID.
85
+
86
+ Your ActiveRecord model would look something like this:
87
+
88
+ ```ruby
89
+ class Shop < ActiveRecord::Base
90
+ def self.store(session)
91
+ shop = Shop.new(domain: session.url, token: session.token)
92
+ shop.save!
93
+ shop.id
94
+ end
95
+
96
+ def retrieve(id)
97
+ shop = Shop.find(id)
98
+ ShopifyAPI::Session.new(shop.domain, shop.token)
99
+ end
100
+ end
101
+ ```
102
+
103
+ By default you will have an in memory store but it really won't work on multi-server environments since
104
+ they won't be sharing the static data that would be required in case your user gets directed to a
105
+ different server by your load balancer.
106
+
107
+ The in memory store also does not behave well on Heroku because the session data would be destroyed
108
+ when a dyno is killed due to inactivity.
109
+
110
+ Changing the `ShopifySessionRepository.storage` can simply be done by editing
111
+ `config/initializers/shopify_session_repository.rb` to use the correct model.
112
+
113
+ ## Set your required API permissions
114
+
115
+ Before making API requests, your application must state which API permissions it requires from the shop it's installed in. These requested permissions will be listed on the screen the merchant sees when approving your app to be installed in their shop.
116
+
117
+ Start by reviewing the documentation on API permission scopes: http://docs.shopify.com/api/tutorials/oauth
118
+
119
+ When you know which ones your app will need, add a scope line to the `config/initializers/omniauth.rb` file.
120
+
121
+ ### Example
122
+
123
+ Make this change to request write access to products and read access to orders:
124
+
125
+ ``` ruby
126
+ Rails.application.config.middleware.use OmniAuth::Builder do
127
+ provider :shopify,
128
+ ShopifyApp.configuration.api_key,
129
+ ShopifyApp.configuration.secret,
130
+ :scope => "write_products,read_orders",
131
+ :setup => lambda {|env|
132
+ params = Rack::Utils.parse_query(env['QUERY_STRING'])
133
+ site_url = "https://#{params['shop']}"
134
+ env['omniauth.strategy'].options[:client_options][:site] = site_url
135
+ }
136
+ end
137
+ ```
138
+
139
+ *Note that you can change your API permission scopes on the fly, but the merchant will have to approve each change and your computed API password will change.*
140
+
141
+ ## After running the generator
142
+
143
+ First, start your application:
144
+
145
+ ``` sh
146
+ $ rails server
147
+ ```
148
+
149
+ Now visit http://localhost:3000 and install your application in a Shopify store. Even if Rails tells you to visit your app at http://0.0.0.0:3000, go to http://localhost:3000.
150
+
151
+ After your application has been given whatever API permissions you requested by the shop, you're ready to start experimenting with the Shopify API.
152
+
153
+ ## Rails 3.0 (as in before 3.1) Support
154
+
155
+ Rails 3.0 (as in before the big changes in 3.1) is supported on a branch of our github repo: https://github.com/Shopify/shopify_app/tree/rails_3.0_support
156
+
157
+ ## Common problems
158
+
159
+ If you are getting the following error:
160
+
161
+ ```
162
+ Faraday::Error::ConnectionFailed error when accessing app.
163
+ ```
164
+
165
+ It probably means that the CA certificate on your computer is out of date. A simple solution on the Mac is to install XCode.
166
+
167
+ If you are getting the following error:
168
+
169
+ ```
170
+ ActiveResource::ForbiddenAccess in HomeController#index
171
+ Failed. Response code = 403. Response message = Forbidden.
172
+ ```
173
+
174
+ It means that you have not set appropriate permissions in your `config/initializers/omniauth.rb` file for what you are trying to do in your HomeController#index action. Example: you set your permissions to 'write_content' because that's what your app will do, but your HomeController#index still has that default code generated by shopify_app which attempts to read products and orders, neither being covered by the 'write_content' scope.
175
+
176
+ ## Questions or problems?
177
+
178
+ http://api.shopify.com <= Read up on the possible API calls!
179
+
180
+ http://ecommerce.shopify.com/c/shopify-apis-and-technology <= Ask questions!
181
+
182
+ http://docs.shopify.com/api/the-basics/getting-started <= Read the docs!
@@ -0,0 +1,16 @@
1
+ Releasing ShopifyApp
2
+
3
+ 1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
+ 2. Update the version of ShopifyApp in lib/shopify_app/version.rb
5
+ 3. Add a CHANGELOG entry for the new release with the date
6
+ 4. Commit the changes with a commit message like "Packaging for release X.Y.Z"
7
+ 5. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
8
+ $ git tag vX.Y.Z REV
9
+ 6. Push out the changes
10
+ $ git push
11
+ 7. Push out the tags
12
+ $ git push --tags
13
+ 8. Build the new .gem from the updated .gemspec
14
+ $ gem build shopify_app.gemspec
15
+ 9. Publish the Gem to gemcutter
16
+ $ gem push shopify_app-X.Y.Z.gem
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib/shopify_app'
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ puts
2
+ puts "Shopify App Generator"
3
+ puts "---------------------"
4
+ puts
5
+ puts "To get started, first register your app as a Shopify Partner:"
6
+ puts
7
+ puts " * Go to http://www.shopify.com/partners and create or login to your Partner account."
8
+ puts
9
+ puts " * Jump over to the Apps tab and hit the 'Create a new app' button"
10
+ puts " (Make sure to set the Application URL to http://localhost:3000/login during development)"
11
+ puts
12
+ puts " * Install the Shopify API gem:
13
+
14
+ $ gem install shopify_api"
15
+ puts
16
+ puts " * Run
17
+
18
+ $ rails generate shopify_app your_app_api_key your_app_secret"
19
+ puts
20
+ puts " * Set up a test shop to install your app in (do this on the Partner site)"
21
+ puts
22
+ puts " * Run $ rails server"
23
+ puts
24
+ puts " * Visit http://localhost:3000 and use the test shop's URL to install this app"
25
+ puts
@@ -0,0 +1,23 @@
1
+
2
+
3
+ What's next?
4
+ ------------
5
+
6
+ Make sure to set the Application URL of the application in your Shopify partner account
7
+ to <tt>http://localhost:3000/login</tt>.
8
+
9
+ Then, start your application with:
10
+
11
+ $ rails server
12
+
13
+ Now visit http://localhost:3000 and install your application in a Shopify store.
14
+
15
+ After your application has been given read or read/write API permission by the
16
+ shop, you're ready to start experimenting with the Shopify API.
17
+
18
+ Questions or problems?
19
+ ----------------------
20
+
21
+ API Reference http://api.shopify.com
22
+ Developer Forums http://forums.shopify.com/categories/9
23
+ Developer Wiki http://wiki.shopify.com/Shopify_App_Development
@@ -0,0 +1,22 @@
1
+ Description:
2
+ This is a generator for creating a basic Shopify application to quickly get
3
+ you started. You can see some examples on how to use the Shopify API.
4
+
5
+ The generator creates a basic sessions controller for authenticating with your
6
+ Shop and a controller called "home" which displays basic information
7
+ about your products, orders and articles.
8
+
9
+ Note: It's recommended to use this on a new Rails project, so that the
10
+ generator won't overwrite/delete some of your files.
11
+
12
+ Usage:
13
+ Pass your API key and then your Secret, which the sessions controller
14
+ will need to authenticate with your shop.
15
+ If you don't have an API key yet, register your application in our
16
+ partner system at http://www.shopify.com/partners
17
+
18
+
19
+ Examples:
20
+ script/generate shopify_app edffbb1bb793e2750686e6f4647a384a abbcee050...
21
+
22
+ This will create a sessions controller and a home controller and views.
@@ -0,0 +1,69 @@
1
+ require 'rails/generators'
2
+
3
+ class ShopifyAppGenerator < Rails::Generators::Base
4
+ argument :api_key, :type => :string, :required => false
5
+ argument :secret, :type => :string, :required => false
6
+
7
+ class_option :skip_routes, :type => :boolean, :default => false, :desc => 'pass true to skip route generation'
8
+
9
+ def self.source_root
10
+ File.join(File.dirname(__FILE__), 'templates')
11
+ end
12
+
13
+ def copy_files
14
+ directory 'app'
15
+ directory 'public'
16
+ directory 'config'
17
+ end
18
+
19
+ def remove_static_index
20
+ remove_file 'public/index.html'
21
+ end
22
+
23
+ def add_config_variables
24
+ return if api_key.blank? || secret.blank?
25
+
26
+ inject_into_file 'config/application.rb', <<-DATA, :after => "class Application < Rails::Application\n"
27
+
28
+ # Shopify API connection credentials:
29
+ config.shopify.api_key = '#{api_key}'
30
+ config.shopify.secret = '#{secret}'
31
+ DATA
32
+ end
33
+
34
+ def add_bootstrap_gem
35
+ gem_group :development, :test do
36
+ gem "less-rails-bootstrap"
37
+ gem 'therubyracer', :platforms => :ruby
38
+ end
39
+ end
40
+
41
+ def add_routes
42
+ unless options[:skip_routes]
43
+ route_without_newline "root :to => 'home#index'"
44
+ route "end"
45
+ route_without_newline " delete 'logout' => :destroy"
46
+ route_without_newline " get 'auth/shopify/callback' => :show"
47
+ route_without_newline " post 'login' => :create"
48
+ route_without_newline " get 'login' => :new"
49
+ route_without_newline "controller :sessions do"
50
+ route "get 'design' => 'home#design'"
51
+ route_without_newline "get 'welcome' => 'home#welcome'"
52
+ end
53
+ end
54
+
55
+ def display_readme
56
+ Bundler.with_clean_env do
57
+ run 'bundle install'
58
+ end
59
+
60
+ readme '../README'
61
+ end
62
+
63
+ private
64
+
65
+ def route_without_newline(routing_code)
66
+ sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
67
+ inject_into_file 'config/routes.rb', "\n #{routing_code}", { after: sentinel, verbose: false }
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ // If you need to customize any bootstrap js, we've placed the un-minified versions in
8
+ // assets/javascripts/bootstrap including the test suite that ships with bootstrap.
9
+ // Love,
10
+ // Shopify
11
+ //
12
+ //= require jquery
13
+ //= require jquery_ujs
14
+ //= require twitter/bootstrap
15
+ //= require_tree .
@@ -0,0 +1,10 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require twitter/bootstrap
7
+ *= require imports
8
+ *= require shopify_app_buttons
9
+ *= require shopify_app
10
+ */