Skip to content

Instantly share code, notes, and snippets.

@bewithdhanu
Last active April 21, 2025 10:25
Show Gist options
  • Save bewithdhanu/e8077e8f81c94facb743c1296d0d02dd to your computer and use it in GitHub Desktop.
Save bewithdhanu/e8077e8f81c94facb743c1296d0d02dd to your computer and use it in GitHub Desktop.
Camps API Integration Guide

Camps API Integration Guide

This guide provides instructions for integrating the Camps API into your Android and iOS applications.

API Endpoints

List Camps

GET /api/camps

Headers:

Authorization: Bearer {user_token}

Android Integration

1. WebView Setup

class CampWebViewActivity : AppCompatActivity() {
    private lateinit var webView: WebView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_camp_webview)

        webView = findViewById(R.id.webView)
        webView.settings.apply {
            javaScriptEnabled = true
            domStorageEnabled = true
        }

        // Add JavaScript interface
        webView.addJavascriptInterface(MyAthelete360Interface(this), "MyAthelete360")
        
        // Load the camps page with token
        val token = "YOUR_USER_TOKEN"
        webView.loadUrl("https://your-domain.com/api/camps", mapOf(
            "Authorization" to "Bearer $token"
        ))
    }
}

2. JavaScript Interface

class MyAthelete360Interface(private val context: Context) {
    @JavascriptInterface
    fun sendEvent(event: String, data: String) {
        when (event) {
            "openLink" -> {
                // Handle registration URL
                val intent = Intent(Intent.ACTION_VIEW, Uri.parse(data))
                context.startActivity(intent)
            }
        }
    }
}

3. Layout XML

<?xml version="1.0" encoding="utf-8"?>
<WebView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

iOS Integration

1. WebView Setup

import UIKit
import WebKit

class CampWebViewController: UIViewController {
    private var webView: WKWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Configure WebView
        let configuration = WKWebViewConfiguration()
        let contentController = WKUserContentController()
        contentController.add(self, name: "MyAthelete360")
        configuration.userContentController = contentController
        
        webView = WKWebView(frame: view.bounds, configuration: configuration)
        webView.navigationDelegate = self
        view.addSubview(webView)
        
        // Load the camps page with token
        let token = "YOUR_USER_TOKEN"
        if let url = URL(string: "https://your-domain.com/api/camps") {
            var request = URLRequest(url: url)
            request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
            webView.load(request)
        }
    }
}

2. Message Handler

extension CampWebViewController: WKScriptMessageHandler {
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        guard let body = message.body as? [String: Any],
              let event = body["event"] as? String else {
            return
        }
        
        switch event {
        case "openLink":
            if let urlString = body["data"] as? String,
               let url = URL(string: urlString) {
                UIApplication.shared.open(url)
            }
        default:
            break
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment